2017-12-14 8 views
0

私のアプリケーションは、5つの異なるボタンをタップすることで、5つの短いビデオ(アプリケーションに格納されている)を再生します。すべての動画を連続して再生する「すべて再生」ボタンが必要です。ここですべてのローカルビデオを連続して再生する方法

は、一つのビデオを再生するための私のコードです:

-(IBAction)playVideo1; 
{ 
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@”video1” withExtension:@"mp4"]; 

AVPlayer *player = [AVPlayer playerWithURL:videoURL]; 

AVPlayerViewController *controller = [[AVPlayerViewController alloc]init]; 
controller.player = player; 
[player play]; 
[self presentViewController:controller animated:YES completion:nil]; 

controller.view.frame = self.view.frame; 

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(playerItemDidReachEnd:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:_currentItem]; 
} 
+0

https://developer.apple.com/documentation/avfoundation/avqueueplayer https://developer.apple.com/これを参照してください。ライブラリ/コンテンツ/サンプルコード/ AVFoundationQueuePlayer-iOS/Introduction/Intro.html – karthikeyan

+0

ありがとうございます@karthikeyan。しかし、それは私のためにあまりにも進んでいた。私はこの初心者です。あなたは特定のコードで私を助けることができると思いますか? – Emily94

+0

https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.htmlを参照してください。 – Mukesh

答えて

0

私は答えに提供されたリンクと、いくつかのgoogleingのおかげで自分自身を見つけることができました。ここで

はAVQueuePlayerを使用して順番にビデオを再生する方法は次のとおりです。

- (IBAction)playAll:(id)sender { 
NSString *firstVideoPath = [[NSBundle mainBundle] pathForResource:@”video1” ofType:@"m4v"]; 
NSString *secondVideoPath = [[NSBundle mainBundle] pathForResource:@"video2” ofType:@"m4v"]; 
NSString *thirdVideoPath = [[NSBundle mainBundle] pathForResource:@"video3” ofType:@"m4v"]; 
NSString *fourthVideoPath = [[NSBundle mainBundle] pathForResource:@"video4” ofType:@"m4v"]; 
NSString *fifthVideoPath = [[NSBundle mainBundle] pathForResource:@"video5” ofType:@"m4v"];  

AVPlayerItem *firstVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:firstVideoPath]]; 
AVPlayerItem *secondVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:secondVideoPath]]; 
AVPlayerItem *thirdVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:thirdVideoPath]]; 
AVPlayerItem *fourthVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:fourthVideoPath]]; 
AVPlayerItem *fifthVideoItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:fifthVideoPath]]; 

queuePlayer = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:firstVideoItem, secondVideoItem, thirdVideoItem, fourthVideoItem, fifthVideoItem, nil]]; 

// create a player view controller 
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init]; 
controller.player = queuePlayer; 
[self presentViewController:controller animated:YES completion:nil]; 
[queuePlayer play]; 
関連する問題