-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to play audio in Background Mode? #19
Comments
@andreasotto for iOS, you need to add this to
Just On Android I don't think you need anything. |
Thank you for your response. I already set the audio key in the UIBackgroundModes array, without any success. As soon as i press the Home Button, the audio fades out to silence. It resumes when i unlock the phone again. I wonder what the difference is between the Ionic-Approach with the backgroundmode-plugin..... |
Android requires the media controller to be ran from a service. Currently it's not set this way. Its possible but would require a little bit of work to refactor a few things to make sure this is done correctly. I'll see if I can get to it in the next week or two. Definitely open to PRs though :) |
Ist this already available? |
This seems to be working on android. I can lock phone and it keeps playing. |
1 similar comment
This seems to be working on android. I can lock phone and it keeps playing. |
Any progress on iOS side ? Ionic 'Background Mode' plugin like behaviour? |
Hi,
|
Different things can be meant by "background" here. The plugin should continue playing if you lock the device screen or minimize the app. If you want a media session with background controls like Spotify (other audio apps) this plugin does not currently support that. It is possible to extend this plugin with that behavior and I have done so but the work is not open source at the moment. |
@bradmartin Is there a way to explicitly prevent the plugin from continuing playing if the screen is locked or the app minimized? I tried to find an open/closed issue for this and only for #107 which came close. |
Any plans to open source that code brad? (background audio controls) |
Working with nativescript-vue, I had to add this to my main.js for it to work. It did not work in the |
Where can I add these changes? |
@kdmakwana43 did you manage to make it work? @germania can you give more detail on your code? Where does As you can see, I have some questions 🙂 |
Below is my main.js, I haven't worked on this project in several months, but it worked when I did. Hope this helps!
|
@germania thanks for your response! Does it work for Android as well? |
@FlawaCLV no, that code is only for iOS. If you are compiling an android app, you will need to wrap that code in an if statement, to only run on iOS. Background audio is difficult on android, I've had to deal with it in a native app before (in Java), and it took weeks to figure everything out (so that it works across all devices, and has media buttons in a notification to control the playback). Here's the section that covers some of it https://developer.android.com/guide/topics/media/mediaplayer#mpandservices |
It's working on iOS simulator but NOT on real device . Could anyone tell why ? |
@bradmartin do you offer this plugin for purchase? |
@mehdinourollah @bipinbipin have you guys found a solution ? My iOS users are really getting pissed off by this 😅 |
@bradmartin I confirm that the audio stops playing if the user lock the device. Any updates on this issue ? |
Good news ! I finally managed to make it work! The solution was to add this code to my iOS Delegate 🙂 MyDelegate.prototype.applicationDidEnterBackground = function (application) {
AVAudioSession.sharedInstance().setCategoryWithOptionsError(
AVAudioSessionCategoryPlayAndRecord,
AVAudioSessionCategoryOptions.DefaultToSpeaker
);
}; |
where did you add this? |
@Bxggi3 I've added it in the App.vue component which is my root component. You need to create a custom delegate and set it: |
@FlawaCLV Do you have any other code preventing the audio from dropping before |
@eloiqs nope, I don't believe so. |
Was something like this ever integrated into this audio plugin? (Having a MediaPlayer in notification tray) |
Also found |
What is the correct way of playing audible content in background?
I'm playing an mp3 in a loop - but as soon as the phone's screen locks, the sound will be stopped.
On Ionic i used the plugin "BackgroundMode" which works perfectly: the sound keeps on playing.
How can that be achived with NativeScript audio?
The text was updated successfully, but these errors were encountered: