标签:i++ 设置 lib 学习 height rom uibutton object hid
请移步如何快速的开发一个完整的iOS直播app(播放篇)
其实里面讲的很详细,我也是参照这个写的Demo。然后在他的基础上加了一点东西。(不废话我直接上我的代码)
1、纯代码Masonry布局
2、集成ijkplayer第三方库,实现拉流播放
3、打包ijkplayer静态库,实现release版真机模拟机的包
4、实现点赞与送礼物特效
其实使用第三方的库简单的实现拉流还是比较简单的。
只要将打包好的IJKMediaFramework包拉到项目,然后导入系统运行所必要的包,比如下图
import<IJKMediaFramework/IJKMediaFramework.h>
// 拉流地址
NSURL *url = [NSURL URLWithString:_model.stream_addr];
// 创建IJKFFMoviePlayerController:专门用来直播,传入拉流地址就好了
IJKFFMoviePlayerController *playerVc = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:nil];
// 准备播放
[playerVc prepareToPlay];
// 强引用,反正被销毁
_player = playerVc;
// 自动调整自己的宽度和高度
playerVc.view.frame = [UIScreen mainScreen].bounds;
playerVc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:playerVc.view atIndex:1];
[playerVc setScalingMode:IJKMPMovieScalingModeAspectFill];
/**
点赞
*/
-(void)showTheLove:(UIButton *)sender{
_heartSize = 36;
DMHeartFlyView* heart = [[DMHeartFlyView alloc]initWithFrame:CGRectMake(0, 0, _heartSize, _heartSize)];
[self.view addSubview:heart];
CGPoint fountainSource = CGPointMake(_heartSize + _heartSize/2.0, self.view.bounds.size.height - _heartSize/2.0 - 10);
heart.center = fountainSource;
[heart animateInView:self.view];
// button点击动画
CAKeyframeAnimation *btnAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
btnAnimation.values = @[@(1.0),@(0.7),@(0.5),@(0.3),@(0.5),@(0.7),@(1.0), @(1.2), @(1.4), @(1.2), @(1.0)];
btnAnimation.keyTimes = @[@(0.0),@(0.1),@(0.2),@(0.3),@(0.4),@(0.5),@(0.6),@(0.7),@(0.8),@(0.9),@(1.0)];
btnAnimation.calculationMode = kCAAnimationLinear;
btnAnimation.duration = 0.3;
[sender.layer addAnimation:btnAnimation forKey:@"SHOW"];
}
/**
送礼物
*/
- (void)showMyPorsche918 {
CGFloat durTime = 3.0;
UIImageView *porsche918 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"porsche"]];
//设置汽车初始位置
porsche918.frame = CGRectMake(0, 0, 0, 0);
[self.view addSubview:porsche918];
//给汽车添加动画
[UIView animateWithDuration:durTime animations:^{
porsche918.frame = CGRectMake(ScreenW * 0.5 - 100, ScreenH * 0.5 - 100 * 0.5, 240, 120);
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(durTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//
[UIView animateWithDuration:0.5 animations:^{
porsche918.alpha = 0;
} completion:^(BOOL finished) {
[porsche918 removeFromSuperview];
}];
});
//烟花
CALayer *fireworksL = [CALayer layer];
fireworksL.frame = CGRectMake((ScreenW - 250) * 0.5, 100, 250, 50);
fireworksL.contents = (id)[UIImage imageNamed:@"gift_fireworks_0"].CGImage;
[self.view.layer addSublayer:fireworksL];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(durTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.5 animations:^{
//没找到设置透明度的方法,有创意可以自己写
// fireworksL.alpha = 0;
} completion:^(BOOL finished) {
[fireworksL removeFromSuperlayer];
}];
});
_fireworksL = fireworksL;
NSMutableArray *tempArray = [NSMutableArray array];
for (int i = 1; i < 3; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"gift_fireworks_%d",i]];
[tempArray addObject:image];
}
_fireworksArray = tempArray;
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(update) userInfo:nil repeats:YES];
}
static int _fishIndex = 0;
- (void)update {
_fishIndex++;
if (_fishIndex > 1) {
_fishIndex = 0;
}
UIImage *image = self.fireworksArray[_fishIndex];
_fireworksL.contents = (id)image.CGImage;
}
界面消失,一定要记得停止播放,不然会引起内存泄漏。
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// 界面消失,一定要记得停止播放
[_player pause];
[_player stop];
[_player shutdown];
[_timer invalidate];
_timer = nil;
}
传送门:LiveDemo
这个代码缺少最重要的自己打包的IJKMediaFramework,需要自己打包,不过我也学习分享文章中的方法 ,将文件分开,你们可以自己打包,也可以去我的百度云中下载。
传送门: IJKMediaFramework
最后,如果有什么疑问或者百度云链接或者GitHub源码链接出现问题,可以留言或者通过邮箱gzd1214@163.com找我
标签:i++ 设置 lib 学习 height rom uibutton object hid
原文地址:http://blog.csdn.net/dec_9314/article/details/54176839