Playing audio when App is backgrounded.

iOS, iPad, iPhone, tvOS specific usage questions
eleanorsp
New Cone
New Cone
Posts: 4
Joined: 01 Oct 2024 15:34

Playing audio when App is backgrounded.

Postby eleanorsp » 05 Dec 2024 18:22

3.6.0 MobileVLCKit for iOS.
iOS 18.1.1 (but I think also down to 16.1)

I am using MobileVLCKit in my App everything is playing really well. I can continue to play the audio even if the App is backgrounded or the Lock Screen on the phone has activated.

While the App is backgrounded most of the time VLCMediaPlayer changes status to VLCMediaPlayerStateBuffering, it is still playing well...

There is one big problem and that is when my App is backgrounded (while it is still playing) and another App starts using the audio on the iPhone.
When my app is foregrounded once again, VLCMediaPlayer it is still thinking it is playing and still has the status of VLCMediaPlayerStateBuffering but there is no audio happening from my App. If I then try to pause or stop VLCMediaPlayer the current media, nothing happens. I cannot get VLCMediaPlayer to return to a paused or stopped state. It's like VLCMediaPlayer has hung...

If I try to set a new VLCMedia instance with VLCMediaPlayer that doesn't work either.

So far, I've been forced to delete the existing VLCMediaPlayer instance and create a new VLCMediaPlayer instance. However I cannot determine if there was some audio playing on another app (while my app is backgrounded and was playing) so I cannot be sure if I need to do such a drastic thing. Besides, the audio will cut out and restart every time I bring the app into the foreground, so the listening experience isn't great.

I've tried to find out how the low level VLC code is notified it should stop playing audio but so far haven't found how it is doing it, or if it is doing it at all!

Can anyone provide any pointers for this?

eleanorsp
New Cone
New Cone
Posts: 4
Joined: 01 Oct 2024 15:34

Re: Playing audio when App is backgrounded.

Postby eleanorsp » 10 Dec 2024 15:43

As a follow up to this, I have got something working. AVAudioSession.interruptionNotification is a useful notification when the media is going to be interrupted. I have found if AVAudioSessionInterruptionTypeKey = .began, I still need to delete the VLCMediaPlayer instance and instantiate a new one but things appear to work. While receiving an AVAudioSessionInterruptionTypeKey = .end, I will be able to restart the stream once the app is foregrounded again. Early days but looking good so far.


Return to “VLC for iOS, iPadOS and Apple TV”

Who is online

Users browsing this forum: No registered users and 8 guests