这个播放器只有 2 个按钮,播放/暂停和全屏,它看起来像一个system player
,如此快速和简单。
我UIWebView and HTML5
在 UIView 里面用过,但是 UIWebView 太慢了,不能全屏播放。
如果这个播放器是一个UIObject
或一些 UIView 的东西,我该如何添加它?
谢谢~
这个播放器只有 2 个按钮,播放/暂停和全屏,它看起来像一个system player
,如此快速和简单。
我UIWebView and HTML5
在 UIView 里面用过,但是 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;
}
您可以在UIView
using中添加视频播放器MPMoviePlayerController
。
这是 Apple 示例代码,它就是这样做的。它可以从互联网流式传输视频以及播放本地电影文件。
您可以通过更改 moviePlayercontrolStyle
属性来更改播放控件。
您可以从下面的链接中找到示例代码
http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
导入以下框架
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import <UIKit/UIKit.h>
在 UIView 或 UIViewController 中添加以下代码 类
videoView
为 UIView
// Url of Video
NSURL *videoURL = [NSURL URLWithString:@"urlOfVideo"];
// Init Player
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
// Add Player in AVPlayerViewController
playerViewController.player = player;
playerViewController.showsPlaybackControls = true;
// Set Frame accoding to view
playerViewController.view.frame = _videoView.bounds;
//Used to Play On start
[playerViewController.player play];
// Add Video in UIView
[_videoView addSubview:playerViewController.view];
我希望它对你有用...