[ios]关于MediaPlayer 播放进度的存取

来源:互联网 发布:北欧发达 知乎 编辑:程序博客网 时间:2024/05/22 03:46
@property (copy, nonatomic)  NSString *vedioimgurl;//视频图片@property (copy, nonatomic)  NSString *vediotitle;//视频标题@property (copy, nonatomic)  NSString *playtime;// 播放时间转换成时分秒后@property (copy, nonatomic)   NSString *  userid; //用户id@property (assign, nonatomic)  float  vediotime; //实际时间@property (copy,nonatomic)  NSString *mvediourl;//视频地址



首先定义数据库,并且创建表

[mp play];        _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
开始播放后,添加计时器

每0.1秒执行updateProgress方法 

//两个时间分别为 实际播放的秒数,存取的进度都是一个vediotime来实现

//第二个是转换过后 时分秒

-(void)updateProgress{        self.vedioTime=mp.currentPlaybackTime;        self.playTime = [NSString stringWithFormat:@"%02li:%02li:%02li",                     lround(floor(self.vedioTime / 3600.)) % 100,                     lround(floor(self.vedioTime / 60.)) % 60,                     lround(floor(self.vedioTime / 1.)) % 60]; }


当视频播放结束时

  [mp stop];    [_timer invalidate];        MvedioDb *mvhis = [MvedioDb shareDataBase];        NSString *mvediourl=[NSString stringWithFormat:@"%@",self.movieURL];    [mvhis insertDataBaseWithImgurl:self.imgurl AndTitle:movieTitle2 Time:self.playTime Playtime:self.vedioTime andMvediourl:mvediourl];
</pre><pre name="code" class="objc"><pre name="code" class="objc">计时器结束,插入数据
在视频播放前  进行一个播放进度的读取
计时器结束,插入数据
在视频播放前  进行一个播放进度的读取
 MvedioDb *mvhis = [MvedioDb shareDataBase]; mp.currentPlaybackTime= [mvhis getvedioTime:movieTitle2];



结束~

0 0
原创粉丝点击