星空网 > 软件开发 > 操作系统

iOS 后台播放音乐

在info.plist文件中添加

iOS 后台播放音乐images/loading.gif' data-original="http://images2015.cnblogs.com/blog/880544/201601/880544-20160115155442007-416146670.png" />

下面是后台播放音频的完整测试代码:

引入文件<AVFoundation/AVFoundation.h>

//后台播放音频设置

    AVAudioSession *session = [AVAudioSession sharedInstance];

    [session setActive:YES error:nil];

    [session setCategory:AVAudioSessionCategoryPlayback error:nil];

    

    //让app支持接受远程控制事件

    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    

    //播放背景音乐

    NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"mp3"];

    NSURL *url = [[NSURL alloc] initFileURLWithPath:musicPath];

    

    // 创建播放器

    player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

    [player prepareToPlay];

    [player setVolume:1];

    player.numberOfLoops = -1; //设置音乐播放次数  -1为一直循环

    [player play]; //播放

 




原标题:iOS 后台播放音乐

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Channel Bakers:https://www.goluckyvip.com/tag/16984.html
Channel Spyder:https://www.goluckyvip.com/tag/16985.html
channeladvisor:https://www.goluckyvip.com/tag/16986.html
ChannelEngine:https://www.goluckyvip.com/tag/16987.html
ChannelMAX:https://www.goluckyvip.com/tag/16988.html
ChannelPilot:https://www.goluckyvip.com/tag/16989.html
淘宝给商家发了个“大红包” :https://www.kjdsnews.com/a/1836561.html
厦门曾厝垵家庭旅馆哪家最好?:https://www.vstour.cn/a/365183.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流