10

AVPlayer がバックグラウンド モードで再生されていることに問題があります。ここや Web のどこにでもいる多くの人たちと同じです。私はうまくいくはずだと思うことをしましたが、まだうまくいきません...私の問題は、AudioSessionとAVPlayerを設定して使用する場所にあると思います。

1)「オーディオ」キーは、Info.plist の UIBackgroundModes にあります。

2) AppDelegate で次のように設定された AudioSession (didFinishLaunchingWithOptions で初期化):

AVAudioSession *audio = [[AVAudioSession alloc]init];
[audio setCategory:AVAudioSessionCategoryPlayback error:nil];
[audio setActive:YES error:nil];

3) AppDelegate にも実装されている AVPlayer (AVAudioPlayer ではない) を使用します。(AudioSession の後、didFinishLaunchingWithOptions で初期化されます)、AudioSession の直後

// Load the array with the sample file
NSString *urlAddress = @"http://mystreamadress.mp3";

//Create a URL object.
self.urlStream = [NSURL URLWithString:urlAddress];  
self.player = [AVPlayer playerWithURL:urlStream];
//Starts playback
[player play];

それでも、アプリがバックグラウンドになるたびに(「ホーム」ボタンを押すと)オーディオが中断されます。

4

1 に答える 1

5

ちなみに、問題はシミュレータだけでした。iOS デバイスで正常に動作します

于 2011-04-07T14:08:43.070 に答える