我试图将AVPlayerItem的AVURLAsset插入AVPlayerItemStatusReadyToPlayAVMutableComposition中,如下所示:

composition_ = [[AVMutableComposition alloc] init];
insertionPoint_ = kCMTimeZero;
item_ = [[AVPlayerItem playerItemWithURL:[NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]] retain];
[item_ addObserver:self forKeyPath:@"status" options:0 context:nil];
player_ = [[AVPlayer playerWithPlayerItem:item_] retain];
[player_ addObserver:self forKeyPath:@"currentItem.duration" options:0 context:nil];


/**
 * append a player-item to our composition
 */
- (void)addItemToComposition:(AVPlayerItem *)item
{
    NSError *error = nil;
    VTRACE(@"item duration: %g", CMTimeGetSeconds(item.duration));
    if (![composition_ insertTimeRange:CMTimeRangeMake(kCMTimeZero, item.duration)
                              ofAsset:item.asset
                               atTime:insertionPoint_
                                error:&error])
    {
        VTRACE(@"error: %@", error);
    }
}

/**
 * simplified value observer callback
 */
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([object isKindOfClass:[AVPlayerItem class]])
    {
        AVPlayerItem *item = (AVPlayerItem *)object;
        //playerItem status value changed?
        if ([keyPath isEqualToString:@"status"])
        {   //yes->
            switch(item.status)
            {
                case AVPlayerItemStatusFailed:
                    VTRACE(@"player item status failed");
                break;
                case AVPlayerItemStatusReadyToPlay:
                    VTRACE(@"player item status is ready to play");
                    [self addItemToComposition:player_.currentItem];
                break;
                case AVPlayerItemStatusUnknown:
                    VTRACE(@"player item status is unknown");
                break;
            }
        }
    }
    else if([object isKindOfClass:[AVPlayer class]])
    {
        if ([keyPath isEqualToString:@"currentItem.duration"])
        {   //yes->
            VTRACE(@"player item duration available");
        }
    }
}

不幸的是,我得到的只是尝试调用AVMutableComposition insertTimeRange:ofAsset:atTime:error:的糟糕消息



我想念什么?

为什么无法将项目插入合成物中?

在检查该AVURLAssetAVPlayerItem时,我还注意到tracks数组已分配但为空。可能是原因,如果是,我如何获取AVURLAsset正确保存有效音轨?

最佳答案

好吧,我从另一个来源得到了答案,但我不喜欢它...

显然,仅可能将本地项( Assets )插入AVMutableComposition,远程项(例如HTTP视频流)将不起作用。

文档没有这样说的事实以及我收到的错误消息没有用的事实似乎是Apple的遗漏。我确实提交了一个错误报告来改善这种情况。

苹果雷达错误ID:10517711

Open Radar bug report

关于iphone - 将HTTP流插入AVMutableComposition,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8318422/

10-13 05:59