-
Notifications
You must be signed in to change notification settings - Fork 146
continuedPlayOnDemand
shixuemei edited this page Sep 22, 2016
·
2 revisions
对于点播文件,可以实现从指定位置开始播放的功能
- 将player的自动播放属性shouldAutoplay设置为NO;
- 监听到MPMediaPlaybackIsPreparedToPlayDidChangeNotification通知时,将currentPlaybackTime设置为期望开始播放的时间点,单位是秒
- 调用play方法,即可从指定位置开始播放
该方法只针对点播文件有效,对于直播无效
//准备播放
NSURL *url = [NSURL URLWithString:@"http://maichang.kssws.ks-cdn.com/upload20150716161913.mp4"];
KSYMoviePlayerController *player = [[KSYMoviePlayerController alloc] initWithContentURL: url];
player.shouldAutoplay = NO;
[player prepareToPlay];
//监听到MPMediaPlaybackIsPreparedToPlayDidChangeNotification
-(void)handlePlayerNotify:(NSNotification*)notify
{
if (!_player) {
return;
}
if (MPMediaPlaybackIsPreparedToPlayDidChangeNotification == notify.name) {
stat.text = [NSString stringWithFormat:@"player prepared"];
_player.currentPlaybackTime = 200; //从200s处开始播放
[_player play];
}
}