ネットワーク遅延なしで AVPlayer でストリーミング ビデオを再生しようとしています。幸いなことに、私たちのアプリには、ビデオを再生する画面の前に進行状況画面があります。この進行状況画面で時間を使ってビデオをプリロードし、次の画面で遅延なく再生できるようにしたいと考えています。
私が思いついた最も有望なアプローチは、AVQueuePlayer を使用して 2 つのビデオを再生することです。聞こえる。SO で読んだことから、n 番目のビデオが完成間近になると、AVQueuePlayer は n 番目 + 1 番目のビデオをバッファリングします。
これを行うための私のコードは次のとおりです。
NSString *blackVideoPath = [[NSBundle mainBundle] pathForResource:@"black10-counting" ofType:@"MOV"];
AVPlayerItem *blackVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:blackVideoPath]];
AVPlayerItem *realVideoItem = [AVPlayerItem playerItemWithURL:_videoWithEffectsURL];
NSArray *theItems = [NSArray arrayWithObjects:blackVideoItem, realVideoItem, nil];
AVQueuePlayer *theQueuePlayer = [AVQueuePlayer queuePlayerWithItems:theItems];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[theItems firstObject]];
AVPlayerLayer* playerLayer = [AVPlayerLayer playerLayerWithPlayer:theQueuePlayer];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];
[theQueuePlayer play];
これにより、最初のビデオが再生されます (デバッグ用に、サウンドトラックをカウントするビデオがあります) が、最後に到達して次の画面 (playerItemDidReachEnd) に進むと、実際のビデオはすぐには再生されません。
URL が正しいことを確認するために、リスト内の blackVideoItem と realVideoItem を逆にすると、「実際の」ビデオのサウンドトラックが聞こえます。
SO をよく検索しましたが、ストリーミング ビデオを遅延なく再生する方法はないようです。私は間違いたいです。