在xcode中运行应用程序中运行音乐 [英] run music in background running application in xcode

查看:91
本文介绍了在xcode中运行应用程序中运行音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在应用程序进入后台时向我发送有关如何运行音乐文件的代码示例。 [iphone 4.1]。

Kindly send me a code sample of how to run the music file when the application goes in the background. [iphone 4.1].

当我的应用程序在后台播放时,我不希望音乐停止,就像itunes音乐一样。

I don't want the music to stop when my application goes in the background just like the itunes music.

最好的问候,

Naveed Butt

Best Regards,
Naveed Butt

推荐答案

将audio添加到UIBackgroundModes在你的PLIST中。

Add "audio" to UIBackgroundModes in your PLIST.

用于在手机锁定时继续播放;

For playback to continue when the phone locks;

#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) { /* handle the error condition */ }

NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) { /* handle the error condition */ }

这篇关于在xcode中运行应用程序中运行音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆