간단하게 비디오만 재생시키는 샘플입니다.
1. .h 파일
@property (strong, nonatomic) NSURL *videoURL;
@property (strong, nonatomic) AVPlayerViewController *avVideoController;
2. Play Video
-(void) playMovie{
self.avVideoController = [[AVPlayerViewController alloc] init];
AVPlayer *player = [AVPlayer playerWithURL:[self localMovieURL]];
self.avVideoController.player = player;
[self.avVideoController.view setFrame:CGRectMake (0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.avVideoController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.avVideoController.player currentItem]];
[player play];
}
-(NSURL *)localMovieURL
{
NSURL *theMovieURL = nil;
NSBundle *bundle = [NSBundle mainBundle];
if (bundle)
{
NSString *moviePath = [bundle pathForResource:@"IMG_0075" ofType:@"MOV"];
if (moviePath)
{
theMovieURL = [NSURL fileURLWithPath:moviePath];
}
}
return theMovieURL;
}
3. DidFinishNotification
- (void)videoPlayBackDidFinish:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter]removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
[self.avVideoController.view removeFromSuperview];
self.avVideoController = nil;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Video Playback" message:@"Just finished the video playback. The video is now removed." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okayAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:okayAction];
[self presentViewController:alertController animated:YES completion:nil];
}
'Developer > iOS' 카테고리의 다른 글
[iOS]WCSession으로 iWatch와 iPhone 데이터 주고 받기 (0) | 2016.08.02 |
---|---|
[iOS]Keychain 이용해서 데이터(UUID) 저장하기 - WrapperClass제공 (0) | 2016.05.02 |
[iOS9] Contacts.framework 연락처, 주소록 불러오기 (2) | 2016.01.08 |
[ios]iOS8 UIAlertController Sample (0) | 2016.01.06 |
[iOS]iOS9 Sportlight 검색 추가하기 (0) | 2016.01.05 |