这个播放器只有2个按钮,播放/暂停和全屏,它看起来像一个系统播放器
,如此快速和简单。
我在 UIView 中使用了 UIWebView 和 HTML5
,但是 UIWebView 太慢了,不能全屏播放。
如果这个播放器是一个 UIObject
或一些 UIView 东西,我该如何添加它?
谢谢~
最佳答案
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/