Keep music app alive in background, iOS and Android?

Solution is a one liner on the iOS Side.

You need this code in either your first view controller's init or viewDidLoad method:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

https://stackoverflow.com/a/9721032/6024667

Swift 3 UIApplication.sharedApplication().beginReceivingRemoteControlEvents()

Swift 4 UIApplication.shared.beginReceivingRemoteControlEvents()

Add this code to AppDelegate.m/AppDelegate.swift inside your iOS/Runner directory, just before the return.


You just need to enable "Audio, Airplay and Picture in Picture" in Xcode as shown below. You need to add the Capability "Background Modes". You can find this in the "Signing & Capabilities" tab:

enter image description here

A detailed instruction you can find in the offical docs: https://developer.apple.com/documentation/avfoundation/media_assets_playback_and_editing/creating_a_basic_video_player_ios_and_tvos/enabling_background_audio