[英]Display playback controls in AVPlayer
I got the answer with description. 我得到了描述的答案。 See here .
看到这里 。 To display system playback controls like play, pause button etc. we need AVPlayerViewController.
要显示播放,暂停按钮等系统播放控件,我们需要AVPlayerViewController。 Below is the implementation in Objective-C.
以下是Objective-C中的实现。
@interface ViewController ()
@property (strong,nonatomic) AVPlayerViewController *avPlayerViewController;
@property (strong,nonatomic) AVPlayer *avPlayer;
@end
- (void)viewDidLoad {
[super viewDidLoad];
//URL for the file. It can be over HTTP or local file URL.
NSURL *folderURL=[NSURL fileURLWithPath:uploadFolderLocation];
NSURL *movieURL=[folderURL URLByAppendingPathComponent:@"video.mp4"];
self.avPlayer = [AVPlayer playerWithURL:movieURL];
self.avPlayerViewController=[[AVPlayerViewController alloc]init];
self.avPlayerViewController.player=self.avPlayer;
}
- (IBAction)playButtonTapped:(id)sender {
//Trigger the video to play
//AVPlayer object can direct its visual output to AVPlayer. AVPlayerVC is a AVPlayerViewController. You can add it via objects in bottom-right corner.
AVPlayerVC *avPLayerVC=[[AVPlayerVC alloc] init];
avPLayerVC.player=self.avPlayer;
[self addChildViewController:self.avPlayerViewController];
[self.view addSubview:self.avPlayerViewController.view];
self.avPlayerViewController.view.frame=self.view.frame;
[self.avPlayerViewController.player play];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.