ijkplayer 拉流简单实现
首先是要自己去打一个IJKPlayer的静态库
1. 去git上下载一个demo,然后通过终端进到你下载的文件夹中
2.通过./init-ios.sh,下载FFMpeg
3. 接下来就是编译FFMpeg,依次 ./compile-ffmpeg.sh clean和./compile-ffmpeg.sh all,(这个过程有点漫长, 耐心等待)
4. 下面就是打包静态库的步骤 . 我打包的方法:
(1). 先在editScheme中改为release
(2). 编译代码进行合并frame文件
(3). 打开下载的项目show in finder 在product里面有真机和模拟器两个文件的地址合并的是叫IJKMediaFramework 的文件
(4). 命令如下lipo -creat "真机路径" "模拟器路径" -output "合并后的文件路径"
(5). 如果生成的不是framework文件就在上面命令后面加一个.framework 我是这样做的.
(6). 最后把生成的文件替换到真机的静态库里面,把真机静态库导入到项目当中.
(7). 导入之后导入头文件IJKMediaFramework.h 编译如果成功就说明集成成功.下面贴上代码:
简单的拉流代码
#import <IJKMediaFramework/IJKMediaFramework.h>
@interface ViewController ()
@property(nonatomic,strong)NSURL *url;
@property(nonatomic,strong)id <IJKMediaPlayback>player;
@property(nonatomic,strong)UIView *playerView;/**< 播放的View*/
@property(nonatomic,strong)UIButton *playButton;/**< 控制播放和暂停的按钮*/
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.url = [NSURL URLWithString:@"你要拉流的地址"];
[self.view addSubview:self.playerView];
UIView *pView = [self.player view];
pView.frame = self.playerView.bounds;
pView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.playerView insertSubview:pView atIndex:1];
[self.player setScalingMode:IJKMPMovieScalingModeAspectFill];
[self.view addSubview:self.playButton];
}
#pragma mark -- /*播放或者暂停点击事件*/
- (void)buttonClick:(UIButton *)button {
button.selected = !button.selected;
if (button.selected) {
[self.player play];
}else {
[self.player pause];
}
}
#pragma mark -- /*懒加载*/
- (id<IJKMediaPlayback>)player {
if (!_player) {
_player = [[IJKFFMoviePlayerController alloc] initWithContentURL:self.url withOptions:nil];
[_player prepareToPlay];
}
return _player;
}
- (UIView *)playerView {
if (!_playerView) {
_playerView = [[UIView alloc] initWithFrame:self.view.frame];
_playerView.center = self.view.center;
_playerView.backgroundColor = [UIColor blackColor];
}
return _playerView;
}
- (UIButton *)playButton {
if (!_playButton) {
_playButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 80, self.view.frame.size.width, 30)];
[_playButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
_playButton.selected = YES;
[_playButton setTitle:@"播放" forState:UIControlStateNormal];
[_playButton setTitle:@"暂停" forState:UIControlStateSelected];
[_playButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _playButton;
}
@end