//1.创建时移对象
mAliyunLiveTimeShift = new AliyunLiveTimeShift();
long currentSeconds = System.currentTimeMillis() / 1000;
//2.设置直播流地址
mAliyunLiveTimeShift.setUrl("http://pull-videocall.aliyuncs.com/timeline/test.m3u8");
//3.设置时移区间地址。
mAliyunLiveTimeShift.setTimeLineUrl("http://pull-videocall.aliyuncs.com/openapi/timeline/query?lhs_start=1&app=timeline&stream=test&format=ts&lhs_start_unix_s_0="
+ (currentSeconds - 5 * 60) + "&lhs_end_unix_s_0=" + (currentSeconds + 5 * 60));
//4.准备时移源。
mPlayer.prepareAsync(mAliyunLiveTimeShift);
//直播时间
@property (nonatomic, assign) NSTimeInterval liveTime;
//播放时间
@property (nonatomic, assign) NSTimeInterval currentPlayTime;
//每60秒更新用户时移时间,设置更新区间url后,可以获取
@property (nonatomic, strong) AliyunPlayerVideoTimeShiftModel *timeShiftModel;
//设置直播数据源
- (void)prepareWithLiveTimeUrl:(NSURL *)liveTimeUrl;
//设置时移区间更新url
- (void)setLiveTimeShiftUrl:(NSString*)liveTimeShiftUrl;
//时移到指定的时间
- (void)seekToLiveTime:(NSTimeInterval)startTime;
//1.设置时移区间更新url,地址需要用当前时间来进行拼写
NSTimeInterval currentSeconds = [[NSDate date] timeIntervalSince1970]; //秒
NSString *currentLive = [NSString stringWithFormat:@"http://push-demo.aliyunlive.com/openapi/timeline/query?app=asr&stream=yunxi&format=ts&lhs_start_unix_s_0=%.0f&lhs_end_unix_s_0=%.0f",(currentSeconds - 5 * 60), (currentSeconds + 5 * 60)];
[self.vodPlayer setLiveTimeShiftUrl:currentLive];
//2\. 准备直播时移播放地址
[self.vodPlayer prepareWithLiveTimeUrl:[NSURL URLWithString:@"http://push-demo.aliyunlive.com/asr/yunxi.m3u8"]];
//3\. 播放成功后可以更新界面UI显示
//开始时间
double start = self.vodPlayer.timeShiftModel.startTime;
//记录总的结束时间
self.vodPlayer.timeShiftModel.endTime
//4\. 拖动seek时移区间,通过进度条计算出来具体的时移时间
[self.vodPlayer seekToLiveTime:(int)(n*sender.value+s)];
原文链接
更多技术干货 请关注阿里云云栖社区微信号 :yunqiinsight