我目前正在使用AVPlayerItem播放来自URL的实况流。我的代码是
- (void)viewDidLoad
{
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://s4.voscast.com:8080/"]];
[playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];
AVPlayer* player = [[AVPlayer playerWithPlayerItem:playerItem] retain];
[player play];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
change:(NSDictionary*)change context:(void*)context {
if ([keyPath isEqualToString:@"timedMetadata"])
{
AVPlayerItem* playerItem = object;
for (AVMetadataItem* metadata in playerItem.timedMetadata)
{
NSLog(@"\nkey: %@\nkeySpace: %@\ncommonKey: %@\nvalue: %@", [metadata.key description], metadata.keySpace, metadata.commonKey, metadata.stringValue);
}
}
}有没有什么方法可以暂停,然后从它停止的地方继续,允许快进,重新开始生活?
发布于 2013-05-27 05:13:42
您可以使用[player pause]和[player play]暂停和恢复流,但不能从作为正常曲目(例如mp3文件)离开的点继续。您可以实现与每个关闭和在汽车收音机上相同的效果。
为了实现这一点,你应该在“暂停”期间在后台缓冲数据流,然后重现它,但我想这是一个相当复杂的过程。我帮不了你。
https://stackoverflow.com/questions/12648720
复制相似问题