objective-c - Objc - 如何像这样在 UIView 中添加视频播放器?

标签 objective-c video mpmovieplayercontroller video-player

这个播放器只有2个按钮,播放/暂停和全屏,它看起来像一个系统播放器,如此快速和简单。

我在 UIView 中使用了 UIWebView 和 HTML5,但是 UIWebView 太慢了,不能全屏播放。

如果这个播放器是一个 UIObject 或一些 UIView 东西,我该如何添加它?

谢谢~

sample video player in app Everyday.me

最佳答案

MPMoviePlayerController 从 iOS 9 开始弃用。 您现在可以使用 AVPlayerViewController 将视频插入 iOS 项目。

例如:

#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>

...

@property (nonatomic, retain) AVPlayerViewController *playerViewController;

...

- (void)viewDidLoad
{

    [super viewDidLoad];

    NSString *stringVideoName = @"video.m4v";
    NSString *stringVideoPath = [[NSBundle mainBundle] pathForResource:stringVideoName ofType:nil];
    NSAssert(stringVideoPath, @"Expected not nil video file");

    NSURL *urlVideoFile = [NSURL fileURLWithPath:stringVideoPath];
    NSAssert(urlVideoFile, @"Expected not nil video url");

    _playerViewController = [[AVPlayerViewController alloc] init];
    _playerViewController.player = [AVPlayer playerWithURL:urlVideoFile];
    _playerViewController.view.frame = self.view.bounds;
    _playerViewController.showsPlaybackControls = YES;

    [self.view addSubview:_playerViewController.view];
    self.view.autoresizesSubviews = YES;

}

关于objective-c - Objc - 如何像这样在 UIView 中添加视频播放器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13816416/

相关文章:

objective-c - 我需要在iPad上播放没有声音的视频

ios - View 显示更改事件(Youtube MPMoviePlayerViewController)

ios - 从字典数组中获取字典值的范围

ios - 是否有可能在2011年以编程方式获取iphone的电话号码?

ios - 使用 Objective C 以编程方式进行约束

android - 如何在Webview中播放Youtube视频?

audio - 如何使用 ffmpeg 库在任何视频中附加新人声而不删除旧人声

android - 使用 setpts 和 atempo 选项的 FFmpeg 命令不匹配音频和视频

ios - 如何使用其标签字段使 UITextField 成为第一响应者

ios - MPMoviePlayer 控件样式栏帧高度