使用AVPlayer音频点播不会在后台工作 [英] Airplay of audio using AVPlayer does not work in the background

查看:277
本文介绍了使用AVPlayer音频点播不会在后台工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的使用AVPlayer类从远程URL音频播放。

I am doing audio playback using the AVPlayer class from a remote URL.

它发挥很好,如果我只是玩到耳机/内置扬声器,但我看到了一些怪事与AirPlay的。

It plays fine if I just play to the headphones/built in speaker, but I am seeing some oddities with AirPlay.

当我改变使用AppleTV的AirPlay播放,它会流音频,但在我的iPhone的音频播放指示器(在顶部的菜单栏上的小'玩'三角)消失了,当我锁定手机,而不是持续的背景下,它会停止。 (当正常播放时,它在后台精细饰演)。

When I change to use an AppleTV for AirPlay, it will stream the audio, but on my iphone the audio playback indicator (the small 'play' triangle in the top menu bar) disappears, and when I lock the phone instead of continuing in the background, it stops. (When playing normally, it plays in the background fine).

为什么没有在后台运行的AVPlayer音频AirPlay的多?

Why is the AVPlayer not working in the background for audio over AirPlay?

这是其他什么看?有没有变通的办法?

Is this what other see? Is there a way around it?

推荐答案

确定 - 我在苹果开发论坛挖,发现一个提示

Ok - I dug through the apple dev forums and found a hint.

如果您使用的是AVPlayer纯音频,并希望它在后台工作,而这样做的AirPlay,你需要禁用 allowsAirPlayVideo 设置。

If you are using AVPlayer for audio only, and want it to work in the background while doing airplay, you need to disable the allowsAirPlayVideo setting.

显然AVPlayer在iOS 5+假定它是通过AirPlay的播放视频,所以不允许一个后台,除非你明确禁用视频的AirPlay。

Apparently AVPlayer on iOS 5+ assumes that it is playing back video via AirPlay, and so does not allow backgrounding, unless you explicitly disable video AirPlay.

一旦你禁用此(即 self.player.allowsAirPlayVideo = FALSE; ),那么你的声音仍然可以通过AirPlay的发挥,但现在它不会被视为视频,仅作为音响等将使一个后台工作。

Once you disable this (i.e. self.player.allowsAirPlayVideo = FALSE;) then your audio will still play via AirPlay, but now it will not be treated as video, only as audio, and so will allow the backgrounding to work.

这篇关于使用AVPlayer音频点播不会在后台工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆