1

インターネット ラジオ ストリームからオーディオをライブでストリーミングするアプリを作成しています。

私はAVPLayerを使用していて、AVAudioSessionなどを作成しています...

AVPlayer には [停止] 機能はなく、[再生] と [一時停止] のみです。したがって、ユーザーがストリームを一時停止するとバッファリングされ、再生をクリックすると、一時停止を押したときに中断したところから開始されます。

質問... オーディオ ストリームを強制的にライブ再生する方法はありますか?

私は本当に数秒以上のバッファリングを望んでいません...

ご協力ありがとうございました!

4

1 に答える 1

1

バッファリングが必要ない場合は、MPMovieviewcontroller を介してストリーミング ライブ オーディオを再生してみてください。

オーディオ/ビデオのライブ ストリーミングに最適なプレーヤーです。私もこのプレーヤーを使用しています

ライブ オーディオ ストリーミングを再生するためのアプリ。あなたのすべての要件はこれと一致すると思います。実装してみる

それを理解してください。実装も簡単です.Hereを使用してストリームオーディオを再生するコードを次に示します

MPMovieviewcontroller:

    NSURL *fileURL=[NSURL URLWithString:geturl];
    NSLog(@"fileURL..%@",fileURL);
    moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
    [moviePlayerController.moviePlayer prepareToPlay];
    moviePlayerController.moviePlayer.shouldAutoplay=YES;
    moviePlayerController.view.frame = self.view.frame;
    [self presentMoviePlayerViewControllerAnimated:moviePlayerController];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MPMoviePlayerDidExitFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
    [moviePlayerController.moviePlayer play];

- (void)MPMoviePlayerDidExitFullscreen:(NSNotification *)notification
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerDidExitFullscreenNotification 
                                                  object:nil];

    [moviePlayerController.moviePlayer stop];
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] 
     removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
     object:player];
    [moviePlayerController dismissMoviePlayerViewControllerAnimated];
}

バックグラウンド再生のために、これらの行を info.plist に追加します。これらも plist に追加します。

ここに画像の説明を入力

于 2012-12-22T05:19:29.020 に答える