在iOS上停止AVPlayer

6
我正在使用AVPlayer播放来自互联网的直播流。AVPlayer可以暂停,但在恢复播放时,它会从暂停的那一刻开始继续播放,就像TiVO一样。AVPlayer没有停止方法。
如何使其继续播放当前正在广播的内容(就像您关闭并重新打开汽车收音机一样)?

这取决于流媒体服务器吗? - onmyway133
4个回答

1

停止一个 AVPlayer

[player replaceCurrentItemWithPlayerItem:nil];

那将释放它及其关联资源所占用的所有内存和处理器资源。就这么简单。

1

-(void)seekToTime:(CMTime)time

使用此方法跳转到文件开头


-1

SeekToTime不会停止音频,因此一旦到达结尾,如果您只调用seekToTime,它将像循环一样重新开始播放。您可以使用下面的版本,并带有回调函数,以便在完成搜索时立即暂停视频/音频,使其同时重置和停止。

[_player seekToTime:CMTimeMake(0, 1) completionHandler:^(BOOL finished) {    [_player pause];
}];

-1
 [player pause];
[item_ removeObserver:self forKeyPath:@"status" context:nil];
[item_ removeObserver:self forKeyPath:@"playbackBufferEmpty" context:nil];
[item_ removeObserver:self forKeyPath:@"playbackLikelyToKeepUp" context:nil];
[item_ removeObserver:self forKeyPath:@"timedMetadata" context:nil];
 player=nil;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接