[英]Get AVPlayer that is current playing the audio
I am using an AVPlayer
, and I would like the user to be able to leave the screen that is controlling the audio, then come back to it with the same audio playing. 我正在使用
AVPlayer
,并且希望用户能够离开控制音频的屏幕,然后以相同的音频播放返回到它。 I have accomplished this, but I can't seem to regain control of the AVPlayer
that is currently playing the audio. 我已经做到了,但是我似乎无法重新获得对当前正在播放音频的
AVPlayer
控制。 It there a call that allows me to get the AVPlayer
that is currently running? 是否有一个电话可以让我获取当前正在运行的
AVPlayer
?
I'm answering my own question because this may be helpful to someone... 我正在回答自己的问题,因为这可能对某人有所帮助...
I created a global AVPlayer
by making it a property of the AppDelegate and initializing it there. 我通过将全局
AVPlayer
设置为AppDelegate的一个属性并在那里对其进行初始化来创建了它。 I then created an instance of the AppDelegate
in my ViewController
, and accessed the global AVPlayer
from there. 然后,我在
ViewController
创建了AppDelegate
的实例,并从那里访问了全局AVPlayer
。 I could leave the screen and come back to it from with in the app, and I still had control of the AVPlayer
. 我可以离开屏幕,然后从应用程序中返回到该屏幕,但我仍然可以控制
AVPlayer
。
I'm not sure if I'm missing something deeper here, but you need to store a reference to the AVPlayer as an instance variable. 我不确定在这里是否缺少更深的内容,但是您需要将对AVPlayer的引用存储为实例变量。
@interface @接口
AVPlayer *player;
@implementation @实现
player = [AVPLayer playerWithPlayerItem:item];
Then you do stuff to the player reference 然后向玩家参考资料
[player doStuff];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.