0

I have a basic iOS AVPlayer configured as follows:

let player = AVPlayer(url: URL(string: <some video file URL>)!)
let controller = AVPlayerViewController()
controller.player = player
self.present(controller, animated: true, completion: { player.play() })

When this code is called with a video URL, a full-screen player opens with visible controls where the video appears and auto-plays. After a few seconds the controls auto-hide, and reappear when the screen is touched. (Tested with XCode 10.0)

Now I want to play audios in the same way, i.e. in full-screen and with the same controls. I saw in the documentation that AVPlayer also accepts mp3 files. Indeed, when I just pass an audio URL to the code above, it displays the control buttons and plays the audio. (NB: I first want things to work just with black screen and will later add a poster image.)

However: unlike with videos, when the controls disappear (for some reason they don't auto-hide but they can still disappear, e.g. maybe after locking/unlocking the screen), they do not reappear upon touching the screen. The user then has no way to pause or exit the player and is forced to kill the app.

How can I make sure that the controls show up when touching the screen?

  • how did you add a poster image? – Razib Mollick Oct 13 '18 at 13:35
  • @RazibMollick I basically followed this: https://stackoverflow.com/a/41581146 – Sébastien Dubois Oct 14 '18 at 06:49
  • Interesting, I check your code, auto hide is not working when playing audio. It is always showing. Did you set anywhere showsPlaybackControls flag? – Razib Mollick Oct 14 '18 at 19:26
  • @RazibMollick indeed, auto-hide does not work for some reason. But some circumstances can still make the controls disappear, e.g. I think if you lock then unlock the screen (I'm not quite sure what exactly.) I haven't changed showsPlaybackControls, i.e it has the default value true. And anyway if that value was false, the controls would never show up, which isn't the case. – Sébastien Dubois Oct 15 '18 at 16:31

0 Answers0