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/ :

여기에 사용 AVQueuePlayer 시퀀스에서 비디오를 재생하는 방법 library/content/samplecode/AVFoundationQueuePlayer-iOS/소개/Intro.html – karthikeyan

+0

감사합니다. @karthikeyan. 그러나 그것은 나를 위해 약간 너무 진보했다. 나는 이것에 초심자이다. 특정 코드로 나를 도울 수 있다고 생각하십니까? – Emily94

+0

다음 링크를 통해 이동하십시오 : https://developer.apple.com/library/content/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html – Mukesh

답변

0

내가 대답 제공된 링크와 일부 googleing에 자신 감사를 찾기 위해 관리 :

여기에 하나의 비디오 재생을위한 내 코드입니다.

- (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]; 
관련 문제