美文网首页
MPMoviePlayerController视频播放

MPMoviePlayerController视频播放

作者: lancely | 来源:发表于2016-04-24 15:56 被阅读185次

需要包含头文件 #import <MediaPlayer/MediaPlayer.h>MediaPlayer.framework

#import <MediaPlayer/MediaPlayer.h>
@property (nonatomic,strong) MPMoviePlayerController *player;

// 本地视频
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
self.player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath:videoPath]];
// 网络视频使用
// NSURL*videoPath = [NSURL URLWithString:@"http://www.xxx.com/1.mp4"]
self.player.view.frame = self.view.frame;
[self.view addSubview:self.player.view];
// 不需要进度条
self.player.controlStyle = MPMovieControlStyleNone;
// 是否自动播放(默认为YES)
self.player.shouldAutoplay = YES;
// 播放本地视频时需要
self.player.movieSourceType = MPMovieSourceTypeFile;
// 开始播放
[self.player play];

相关文章

网友评论

      本文标题:MPMoviePlayerController视频播放

      本文链接:https://www.haomeiwen.com/subject/nfefrttx.html