IOS 播放音频

-(void) playSound{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"in" ofType:@"caf"];
    if (path) {
        //注册声音到系统
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&shake_sound_male_id);
        AudioServicesPlaySystemSound(shake_sound_male_id);
        //AudioServicesPlaySystemSound(shake_sound_male_id);//如果无法再下面播放,可以尝试在此播放
    }
    
    AudioServicesPlaySystemSound(shake_sound_male_id);   //播放注册的声音,(此句代码,可以在本类中的任意位置调用,不限于本方法中)
    //AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);   //让手机震动
}

 

posted on 2015-07-08 09:47  大木哥  阅读(245)  评论(0编辑  收藏  举报

导航