2010-10-23 119 views
-4

請向我發送如何在應用程序在後臺運行時運行音樂文件的代碼示例。 [iphone 4.1]。在後臺運行音樂在xcode中運行應用程序

當我的應用程序像itunes音樂一樣在後臺播放時,我不希望音樂停止。

最好的問候,
納維德·巴特

+8

'這就是我想要的,爲我創造。' – Emil 2010-10-23 21:05:32

回答

1

添加「音頻」,以UIBackgroundModes在PLIST。

用於在手機鎖定時繼續播放;

#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 */ } 
+0

不要在模擬器上測試,這在設備上正常工作。 http://stackoverflow.com/questions/3421128/how-do-you-use-avaudioplayer-to-play-music-while-in-the-background?rq=1 – justinkoh 2012-08-14 04:10:34

0

你可以看到埃裏卡喪盾書樣本 - 如何播放音頻文件...