次のコードは、find だけでオーディオをストリーミングするコードです。
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringURL]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
player.numberOfLoops = 0;
player.volume = 1.0f;
[player prepareToPlay];
if (playerError) {
NSLog(@"audio player error: %@", [playerError localizedDescription]);
}
if (player == nil)
NSLog(@"%@", [playerError description]);
else
[player play];
アプリをバックグラウンド モードにしようとすると、再生が停止します。.plist に入り、必要なバックグラウンド モード、アイテム 0、アプリがオーディオを再生します。これで問題は解決しませんでした。
私はこれを置き始めました:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];
[[AVAudioSession sharedInstance] setActive:YES
error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
の中に
- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidEnterBackground:(UIApplication *)application
と
メインViewControllerのviewDidLoad内。[player prepareToPlay] の直後も同様です。
問題が適切なバックグラウンド設定を設定していないのか、アプリが接続を切断しているのかはわかりません. 基本的に、何が欠けているのかわかりません。
私は見てきました:
と
編集:誰か?