gpt4 book ai didi

ios - 在 AVPlayer 中显示播放控件

转载 作者:可可西里 更新时间:2023-11-01 04:41:04 27 4
gpt4 key购买 nike

我可以运行视频,但看不到暂停等控制按钮和与视频交互的 slider 。询问了类似的查询(see here),但我没有遵循答案。

最佳答案

我得到了描述的答案。 See here .要显示播放、暂停按钮等系统播放控件,我们需要 AVPlayerViewController。下面是在 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];
}

带有控制按钮的视频图像: enter image description here

关于ios - 在 AVPlayer 中显示播放控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36436311/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com