初始化
(instancetype)initWithContentURL:(NSURL *)url
本地文件:
[[NSBundle mainBundle]URLForAuxiliaryExecutable:]
[NSURL fileURLWithPath:]
网络文件:
[NSURL URLWithstring:]
准备工作
- call the prepareToPlay method
- registerMPMoviePlayerLoadStateDidChangeNotification notification
- check load state by accessing the loadState property
- 配置属性
movieSourceType(可以加快加载速度)
fullscreen (是否全屏)
scalingMode (适屏模式)
controlStyle (控制界面)
属性
duration (时长)
playableDuration (已播放)
view (播放视图)
backgroundView (可自定义播放控制)
initialPlaybackTime 视频播放的起始点
(关于解决iOS貌似不支持到问题)
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerLoadStateDidChangeNotification
object:nil queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
if (IOSSystemVersion >= 6.0) {
if (moviePlayerView.moviePlayer.playbackState == MPMoviePlaybackStatePlaying) {
[moviePlayerView.moviePlayer setCurrentPlaybackTime:initialPlaybackTime];
}
}
}];
endPlaybackTime 视频播放的结束点
缓存属性
NSArray *events = playerViewController.moviePlayer.accessLog.events;
int count = events.count;
for (int i = 0; i < count; i++)
{
MPMovieAccessLogEvent *currentEvent = [events objectAtIndex:i];
double byts = currentEvent.indicatedBitrate;
int64_t byte = currentEvent.numberOfBytesTransferred;
int64_t bytes = currentEvent.numberOfBytesTransferred >> 10;
NSMutableString *strBytes = [[NSMutableString alloc] initWithCapacity:100];
[strBytes appendFormat:@"totalSize = %d byte", bytes];
if (bytes > 1024)
{
bytes = bytes >> 10;
[bytesS setString:@""];
[bytesS appendFormat:@"total = %d M", bytes];
}
NSLog(@"byte = %f M bytes = %lld", (float)byte / (1024 * 1024), bytes);
}
在播放代码[player play];之后,New一个timer执行上面的代码。
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(moviePlay) userInfo:nil repeats:YES];
协议控制
MPMediaPlayback 不需要delegate,只用遵守协议方法即可