我在使用AVURLAsset时遇到了问题。
NSString * const kContentURL = @
"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
...
NSURL *contentURL = [NSURL URLWithString:kContentURL];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:contentURL
options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey]
completionHandler:^{
...
NSError *error = nil;
AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey
error:&error];
...
}在完成块中,状态为AVKeyValueStatusFailed,错误消息为"Cannot Open“。我见过的所有示例都使用本地文件,所以使用远程文件可能会有问题……
问候你,昆汀
发布于 2011-02-09 00:05:49
您不能像苹果的AV Foundation Programming Guide中所说的那样,直接为HTTP Live流创建AVURLAsset。您必须使用流url创建一个AVPlayerItem,并使用它实例化一个AVPlayer
AVPlayerItem *pItem = [AVPlayerItem playerItemWithURL:theStreamURL];
AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];如果您需要访问后面的AVURLAsset,可以按照以下步骤操作。
步骤1/注册播放器项的status属性的更改
[playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];第2步/在observeValueForKeyPath:ofObject:change:context:中
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"status"]) {
AVPlayerItem *pItem = (AVPlayerItem *)object;
if (pItem.status == AVPlayerItemStatusReadyToPlay) {
// Here you can access to the player item's asset
// e.g.: self.asset = (AVURLAsset *)pItem.asset;
}
}
}编辑:更正了答案
https://stackoverflow.com/questions/4934886
复制相似问题