AVPlayerItem暂停直播网址?

时间:2012-09-28 23:55:21

标签: iphone xcode audio audio-streaming avplayer

我目前正在使用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);
        }
    }
}

有什么方法可以暂停,然后从它停止的地方恢复,允许快进以恢复生活?

1 个答案:

答案 0 :(得分:0)

您可以使用[player pause][player play]来暂停和恢复流式传输,但无法从您作为普通音轨留下的点(例如mp3文件)恢复。您可以达到与关闭和汽车收音机相同的效果。

为了达到这个目的,你应该在“暂停”期间在后台缓冲流,然后重现它,但我想这很复杂。我帮不了你。