登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

ScreenRecord iOS 屏幕录制

[复制链接]
来自: 李世铿 分类: iOS精品源码 上传时间: 2016-5-6 17:33:36

项目介绍:

iOS 9.0 新增的接口,屏幕录制,声音录制,可以选择是否启用麦克风录入外围环境声音。
已经封装好为一个类,直接在项目中拖入就可以使用。

使用方法:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <ReplayKit/ReplayKit.h>
#import "GameScreenRecoder.h"

@interface ViewController ()<GameScreenRecoderDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *backImageView;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (strong,nonatomic)AVAudioPlayer * player;
@property (nonatomic,strong)NSTimer * timer;
@property (weak, nonatomic) IBOutlet UILabel *flagLabel;
@end

@implementation ViewController
-(NSTimer *)timer{
    if (_timer == nil) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeBegin) userInfo:nil repeats:YES];
    }
    return _timer;
}
-(void)timeBegin{
    _timeLabel.text = [NSString stringWithFormat:@"%ld",[_timeLabel.text integerValue]+1];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    UIImage * image1 = [UIImage imageNamed:@"0.png"];
    UIImage * image2 = [UIImage imageNamed:@"1.gif"];
    self.backImageView.animationImages = @[image1,image2];
    self.backImageView.animationDuration = 3.0;
    self.backImageView.animationRepeatCount = 0;
    [self.backImageView startAnimating];
    [self createMusic];
    [self.timer fire];
    [GameScreenRecoder INSTANCE].delegate = self;
    self.flagLabel.text = @"状态";
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc{
    [self.timer invalidate];
    self.timer = nil;
}
- (IBAction)startRecord:(id)sender {
    //同时开启音乐
    [_player play];
    if ([GameScreenRecoder startRecord:YES]) {
        [self.timer fire];
        NSLog(@"开始录制");
    }
}
- (IBAction)endRecord:(id)sender {
    [_player stop];
    [GameScreenRecoder  stopRecord];
    self.flagLabel.text = @"录制结束";
    [self.timer invalidate];
    self.timer = nil;
     NSLog(@"结束");
}
#pragma mark -Delegate
-(void)loading{
    self.flagLabel.text = @"准备中";
}
-(void)loadEnd{
    self.flagLabel.text = @"正在录制";
}
-(void)showSuccessViewController{
    
}
- (void)previewControllerDidFinish:(RPPreviewViewController *)previewController{
    NSLog(@"%s",__FUNCTION__);
    NSLog(@"%@",previewController);
    [previewController dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}
- (void)previewController:(RPPreviewViewController *)previewController didFinishWithActivityTypes:(NSSet <NSString *> *)activityTypes{
    NSLog(@"展示视图的内容%@",activityTypes);
    if ([activityTypes containsObject:@"com.apple.UIKit.activity.SaveToCameraRoll"]) {
        NSLog(@"已保存到用户相册,如果有需要可以提示用户,弹出一个对话框");
    }
    //"com.apple.UIKit.activity.CopyToPasteboard"拷贝了该文件
    
}
#pragma mark -音乐播放
-(void)createMusic{
    NSURL * url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"a" ofType:@"mp3"]];
    AVAudioPlayer * player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
    player.volume = 1.0;
    self.player = player;
    [player prepareToPlay];
  
}

@end

DEMO下载:

相关源码推荐:

我来说两句
*滑动验证:
所有评论(148)
赵涂涂 2016-5-6 18:00:25
楼主威武啊,Code4App有你更给力!
回复
梁辉 2016-5-6 21:06:13
顶!!!!楼主威武!!!!!
回复
Lockegyz 2016-5-7 08:44:54
楼主威武啊,Code4App有你更给力!
回复
只有一点点 2016-5-7 11:48:02
强烈支持楼主ing……
回复
LancCJ 2016-5-7 15:38:35
新手来袭 支持下
回复
bobjy 2016-5-7 21:04:09
感谢分享,Code4App有你更精彩:)
回复
bobjy 2016-5-7 21:10:45
精华内容,楼主V5!
回复
alway991 2016-5-9 09:28:52
感谢分享,Code4App有你更精彩:)
回复
半吱湮 2016-5-9 09:33:05
学习学习!
回复
提取码:  下载次数:249 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
5780 2 249
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表