gpt4 book ai didi

cocoa - 为什么加载后 AVURLAsset 的 track 数组为空?

转载 作者:行者123 更新时间:2023-12-03 16:17:57 27 4
gpt4 key购买 nike

我正在尝试获取 AVURLAsset 视频轨道的自然大小。因此,我使用 loadValuesAsynchronouslyForKeys:completionHandler: 加载资源 tracks。在完成处理程序中,当状态为 AVKeyValueStatusLoaded 时,我查看 asset.tracks,它是空的。我期望至少找到一个音频和一个视频轨道。为什么轨道数组为空?

这是我的代码:

#import <AVFoundation/AVFoundation.h>

int main(int argc, char *argv[])
{
__block BOOL loaded = NO;
AVURLAsset *asset;
@autoreleasepool
{
NSURL *url = [NSURL URLWithString:@"https://devimages.apple.com.edgekey.net/resources/http-streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8"];
asset = [AVURLAsset URLAssetWithURL:url options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^{
loaded = YES;
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error = nil;
AVKeyValueStatus status = [asset statusOfValueForKey:@"tracks" error:&error];
if (status == AVKeyValueStatusLoaded)
NSLog(@"asset.tracks (%ld): %@", [asset.tracks count], asset.tracks);
else
NSLog(@"error (%ld): %@", status, error);
});
}];
}

while (!loaded)
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];

return 0;
}

在 Mountain Lion 10.8.1 上运行此代码会记录以下内容:

asset.tracks (0): (
)

更新 有些人指出我可能无法获取轨道,因为我使用的是 HTTP Live Streaming URL。因此,任何获取当前播放视频大小的方法(无论是否使用轨道)都是可以接受的答案。

最佳答案

由于 Assets 是通过 HTTP Live Streaming 提供的,因此它没有任何轨道。检索视频大小的另一种方法是使用 KVO 观察播放器项目 presentationSize 属性:

AVPlayer *player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:asset]];
[player addObserver:self forKeyPath:@"currentItem.presentationSize" options:NSKeyValueObservingOptionNew context:NULL];

关于cocoa - 为什么加载后 AVURLAsset 的 track 数组为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12450889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com