Skip to content

continuedPlayOnDemand

shixuemei edited this page Sep 22, 2016 · 2 revisions

描述

对于点播文件,可以实现从指定位置开始播放的功能

使用方法

  1. 将player的自动播放属性shouldAutoplay设置为NO;
  2. 监听到MPMediaPlaybackIsPreparedToPlayDidChangeNotification通知时,将currentPlaybackTime设置为期望开始播放的时间点,单位是秒
  3. 调用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];
    }
}
Clone this wiki locally