gpt4 book ai didi

ios - AVPlayer 在长时间延迟后开始重现视频

转载 作者:行者123 更新时间:2023-11-28 18:29:04 31 4
gpt4 key购买 nike

延迟大约 10 秒。我的代码片段。这是 HomeController 的 *.m 文件:

@interface HomeController ()
@property(nonatomic, strong) AVPlayerViewController *playerViewController;
@implementation HomeController
- (void)viewDidLoad
{
[super viewDidLoad];
...
self.playerViewController = [[AVPlayerViewController alloc] init];
}
- (IBAction)watchDemoToggle:(id)sender {
NSURL *url = [NSURL URLWithString:@"http://blahblahblah.com/demo.mp4"];
AVURLAsset *asset = [AVURLAsset assetWithURL: url];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
if(playerItem)
{
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
self.playerViewController.player = player;
[self.playerViewController.player addObserver:self forKeyPath:@"status" options:0 context:nil];
[self.playerViewController setShowsPlaybackControls:NO];
[self presentViewController:self.playerViewController animated:YES completion:^{
[self.playerViewController.player play];
self.playerViewController.showsPlaybackControls = YES;
}];
}
}

#pragma mark - KVO
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([keyPath isEqualToString:@"status"]) {
AVPlayerStatus status = [change[NSKeyValueChangeNewKey] integerValue];
NSLog(@"status = %ld", (long)status);
}
}

我添加了 KVO 并得到的结果是点击播放后播放器状态为 AVPlayerStatusUnknown。之后,尽管视频正在重现,但它并没有改变。有人知道吗?

最佳答案

将 AVPlayer 的 automaticallyWaitsToMinimizeStalling 属性设置为 false 以便立即开始播放。

AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
player.automaticallyWaitsToMinimizeStalling = false;

但如果没有足够的内容可供播放,则播放器可能会停止。

有关详细信息,请参阅此 Apple 文档。

avplayer

关于ios - AVPlayer 在长时间延迟后开始重现视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39703808/

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