首页 > 其他 > 详细

在应用程序中播放声音

时间:2015-05-12 18:49:42      阅读:106      评论:0      收藏:0      [点我收藏+]
NSString *path = nil;
path = [[NSBundle mainBundle] pathForResource:@"occasion" ofType:@"aiff"];NSURL * url = [NSURL URLWithString:path];
        SystemSoundID soundID;
       
        AudioServicesCreateSystemSoundID((
__bridge CFURLRef)url, &soundID);
        AudioServicesPlaySystemSound(soundID);
receiveGiftCard
receiveGiftCard


-(void) playSound

{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"shake_sound_male" ofType:@"wav"];
    if (path) {
        //注册声音到系统
        AudioServicesCreateSystemSoundID((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);   //让手机震动
}

在应用程序中播放声音

原文:http://blog.csdn.net/mr__hacker/article/details/45673115

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!