Open yukihiro-m-play opened 3 years ago
We would appreciate if you could response to my question. The detail procedure and expected behavior are as follows.
We expect the audio to be output continuously (background playback) by the following procedure, but the audio stops without continuing.
Perform the following as Xcode settings. Turn on "Capabilities" > "Background Modes" in Target of Xcode and check "Audio, AirPlay and Picture in Picture".
Implement AVAudioSession.setCategory(AVAudioSessionCategoryPlayback).
(void)viewDidAppear:(BOOL)animated { ENTER(); [super viewDidAppear:animated];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:true error:nil]; }
Implement release the layer of Shaka Player.
(void)viewDidLoad { ENTER(); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil]; }
(void)didEnterBackground:(NSNotification *)notification { ENTER(); [_shakaPlayerView setPlayer:nil]; _shakaPlayerView = nil; }
Play clear mpd file with Shaka Player.
Press the home button and the application enter the background.
How to continue playing audio when the app enter background? Also, We want the app to control whether background playback is enabled or disabled, is that possible?
Make sure that the ShakaPlayer
instance still has another reference. If you only store it in the ShakaPlayerView
, then when you remove it, the ShakaPlayer
will be destroyed.
My guess is the OS is killing the process since we don't use iOS' thread scheduling to schedule background work. We may need to schedule some background tasks so the process keeps running. If we have to use iOS background tasks for all background work, this will be really difficult to add. We may be able to just schedule some fake events to keep the process alive.
I just append more description about problem from logs. This errors show when app is moved background:
E1223 09:24:17.956127 1871097856 apple_decoder.cc:629] Error decoding frames: -12903
Got Shaka Player Error: Error decoding frames: -12903
Got Shaka Player Error: Shaka Error, Category: 3, Code: 3016
... workaround hack is to switch to native AV player during background and returning to shaka after app has moved back to foreground..
I tried the following in order to continue playing audio in the background, but the playback is paused when the iOS application enter background.
How to continue playing when the app enter background?