简体   繁体   English

在AVPlayer中显示播放控件

[英]Display playback controls in AVPlayer

I am able to run the video, but I am not able to see the control buttons like pause and the slider to interact with the video. 我能够运行视频,但我无法看到像暂停和滑块这样的控制按钮与视频交互。 Similar query is asked ( see here ) but I do not follow the answer. 询问类似的查询( 见这里 ),但我没有按照答案。

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];
   }

The image of the video with control buttons: 带控制按钮的视频图像: 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM