首页 > 移动平台 > 详细

iOS_33_音乐后台播放

时间:2014-09-10 23:57:21      阅读:581      评论:0      收藏:0      [点我收藏+]
音乐后台播放:三个步骤
在appDelegate中的didEnterBackground方法中实现:

app的beginBackgroundTaskWithExpirationHandler方法

开启后台任务,让程序在后台运行

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    // 后台播放三步骤之一:让应用在后台运行
    [application beginBackgroundTaskWithExpirationHandler:nil];
}


bubuko.com,布布扣
在Supporting Files目录下的【33_音效-Info.plist】
增加一项【Required background modes】
值为【App plays audio or streams audio/video using AirPlay】
bubuko.com,布布扣
bubuko.com,布布扣
第三、在工具类的初始化方法【

initialize】中,设置音频会话的类型,并激活

bubuko.com,布布扣
+ (void)initialize
{
    // 后台播放,第三步,设置 音频会话类型
    AVAudioSession *session = [AVAudioSession sharedInstance];
    // 类型是:播放和录音
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    // 而且要激活 音频会话
    [session setActive:YES error:nil];
}


其他三种常用的音频会话类型是:
bubuko.com,布布扣

iOS_33_音乐后台播放

原文:http://blog.csdn.net/pre_eminent/article/details/39188759

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