How to AVPlayer Movie File Play
How to AVPlayer MOV File
OverLay Tool is display
OverLay Tool is display
-(IBAction)btnPlayTouch:(id)sender
{
// Movie File Plat Test
NSString *movieFilePath = [[NSBundle mainBundle] pathForResource:@"IMG_2614" ofType:@"MOV"];
NSURL *url = [NSURL fileURLWithPath:movieFilePath];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
player = [AVPlayer playerWithPlayerItem:playerItem];
float durationSeconds = asset.duration.value/asset.duration.timescale;
[sldDuration setMaximumValue:durationSeconds];
sldDuration.value = 0;
NSArray *visualTracks = [asset tracksWithMediaCharacteristic:AVMediaCharacteristicVisual];
if ((!visualTracks) || ([visualTracks count] == 0)) {
NSLog(@"not Moview File");
} else {
// 레이어 선언
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
// 크기 조정
playerLayer.frame = playView.bounds;
//playerLayer.frame = CGRectMake(0, 0, 480, 320);
// 크기에 동영상 맞추기
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
// 동영상 추가
[playView.layer addSublayer:playerLayer];
//[self.view.layer addSublayer:playerLayer];
// 동영상 재생
[player play];
// 재생 상태 표시
sliderTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateSlider:) userInfo:nil repeats:YES];
}
}
댓글
댓글 쓰기