标签:atomic str 对象 uiview init png ide 方便 div
1.先导入IJKMediaFramework框架
集成好的包,不用再去麻烦了,直接拉到项目中即可, 地址http://pan.baidu.com/s/1ge8jxE7 ,有点大,但以后用到方便
2.导入相关framework和库
如图:
3. 导入头文件
#import <IJKMediaFramework/IJKMediaFramework.h>
4. 设置代理
@property(nonatomic, retain)id<IJKMediaPlayback>Play;
5. 地址URL
NSURL *starUrl = [NSURL URLWithString:@""];
6.创建一个播放器对象
_Play = [[IJKFFMoviePlayerController alloc] initWithContentURL:_starUrl withOptions:nil];
7.通过代理对象返回一个播放视频的MadieView
[self setupMadieView];
8. 准备播放
_Play prepareToPlay];
9. 开始播放
[_Play play];
就可以播放了,停止的话调用 [_Play stop];
总的代码如下:
1 #import "ViewController.h" 2 #import <IJKMediaFramework/IJKMediaFramework.h> 3 4 @interface ViewController () 5 @property(nonatomic, retain)id<IJKMediaPlayback>Play; 6 @property (nonatomic, weak) UIView *MadieView; 7 @end 8 9 @implementation ViewController 10 11 - (void)viewDidLoad { 12 [super viewDidLoad]; 13 //地址URL 14 NSURL *starUrl = [NSURL URLWithString:@"http://wvideo.spriteapp.cn/video/2016/1117/582d39fa63e2b_wpd.mp4"]; 15 16 //创建一个播放器对象 17 _Play = [[IJKFFMoviePlayerController alloc] initWithContentURL:starUrl withOptions:nil]; 18 19 //通过代理对象返回一个播放视频的View 20 [self setupMadieView]; 21 22 //准备播放 23 [_Play prepareToPlay]; 24 25 //开始播放 26 [_Play play]; 27 } 28 29 //通过代理对象返回一个播放视频的view 30 - (void)setupMadieView { 31 32 //通过代理对象view返回一个MadieView 33 UIView *MadieView = [_Play view]; 34 _MadieView = MadieView; 35 36 //横竖屏适配 37 MadieView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 38 39 MadieView.frame = self.view.frame; 40 41 [self.view addSubview:MadieView]; 42 } 43 44 @end
标签:atomic str 对象 uiview init png ide 方便 div
原文地址:http://www.cnblogs.com/loveDodream-zzt/p/6100223.html