简体   繁体   中英

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. I have accomplished this, but I can't seem to regain control of the AVPlayer that is currently playing the audio. It there a call that allows me to get the AVPlayer that is currently running?

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. I then created an instance of the AppDelegate in my ViewController , and accessed the global AVPlayer from there. I could leave the screen and come back to it from with in the app, and I still had control of the 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.

@interface

AVPlayer *player;

@implementation

player = [AVPLayer playerWithPlayerItem:item];

Then you do stuff to the player reference

[player doStuff];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM