AVPlayer 一直在后台运行

发布于 2024-11-18 03:02:38 字数 677 浏览 1 评论 0原文

我正在使用 AVPlayer 播放在线电影。它运行良好。现在的问题是,当我在电影开始播放之前从视图中弹出时,后台进程会继续运行。当电影加载后,它开始在后台播放。

我尝试在 viewWillDisappear 中释放播放器。但它不起作用。

- (void)viewWillDisappear:(BOOL)animated
{
    if (self.player.currentItem.status != AVPlayerItemStatusReadyToPlay) 
    {
        [self.player.currentItem removeObserver:self forKeyPath:kRateKey];
        [self.player.currentItem removeObserver:self forKeyPath:kStatusKey];
        [self.player.currentItem removeObserver:self forKeyPath:kTimedMetadataKey];
    }
    [self.player pause];
    [self.player release];
    [self.playerLayerView release];

    [super viewWillDisappear:animated];
}

有人可以帮忙吗? 提前致谢

I am using AVPlayer to play online movie. It is working fine. Now the problem is, when I pop out from the view before the movie starts playing, the background process keeps running. And when the movie gets loaded, it starts playing in background.

I tried to release the player in viewWillDisappear. But its not working.

- (void)viewWillDisappear:(BOOL)animated
{
    if (self.player.currentItem.status != AVPlayerItemStatusReadyToPlay) 
    {
        [self.player.currentItem removeObserver:self forKeyPath:kRateKey];
        [self.player.currentItem removeObserver:self forKeyPath:kStatusKey];
        [self.player.currentItem removeObserver:self forKeyPath:kTimedMetadataKey];
    }
    [self.player pause];
    [self.player release];
    [self.playerLayerView release];

    [super viewWillDisappear:animated];
}

Can anyone please help?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2024-11-25 03:02:38
- (void)viewWillDisappear:(BOOL)animated
        if (self.player.playing==YES) {
            [self.player stop];
            self.player=nil;
        }
    }
- (void)viewWillDisappear:(BOOL)animated
        if (self.player.playing==YES) {
            [self.player stop];
            self.player=nil;
        }
    }
心凉怎暖 2024-11-25 03:02:38

这可能会有所帮助..

    if (self.player.currentItem.playbackLikelyToKeepUp == 1 ) {

    NSLog(@"Ready To Play");
    [self.player play];


    }else{

    NSLog(@" Show HUD Buffering...");

    [self.player pause];

    }

This might help..

    if (self.player.currentItem.playbackLikelyToKeepUp == 1 ) {

    NSLog(@"Ready To Play");
    [self.player play];


    }else{

    NSLog(@" Show HUD Buffering...");

    [self.player pause];

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文