2012-09-28 41 views
1

我目前使用AVPlayerItem从URL播放实时流。我的代码是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); 
     } 
    } 
} 

有没有什么办法,这是可以暂停,然后恢复正确的地方,在离开的,允许快进到重新站起来的生活吗?

回答

0

您可以使用[player pause][player play]来暂停和恢复流式传输,但不能从您作为普通曲目离开的位置(例如mp3文件)继续播放。您可以达到与每次关闭和在车载收音机上相同的效果。

为了达到这个目的,你应该在“暂停”期间缓冲背景中的数据流,然后重现它,但我认为它很复杂。我不能帮你。