I am creating one music app which will get songs using API. Songs are playing perfectly but its not working in background. When I close the app audio gets stop. I am creating this app with ionic framework and using cordova Media plugin. I have googled many things but not able to resolve the issue.
Shall I need to use some other plugin instead of cordova Media. Please give some suggestion.
Note: I need only for android devices
I didn't get any solution. So I have created one plugin for it. Please refer this link Cordova Plugin - Back As Home
What exactly it's doing?
Instead of closing the app, it's minimizing it. So this code will help back button to work as home button.
Add Plugin
cordova plugin add https://github.com/amitsinha559/cordova-plugin-back-as-home.git
Add this codes in .run if you want to work back as home button
$ionicPlatform.registerBackButtonAction(function(e){
backAsHome.trigger(function(){
console.log("Success");
}, function(){
console.log("Error");
});
e.preventDefault();
},101);
If you want to use in some button action
$scope.someButton = function() {
backAsHome.trigger(function(){
console.log("Success");
}, function(){
console.log("Error");
});
}
Please let me know if you are facing any issue.
The OS will put the screen and the CPU to sleep unless you acquire a wakelock - Partial wakelock in your case.
There are two attempts to prevent cordova apps from sleeping, or run in the background. Have a look at those plugins.
https://github.com/katzer/cordova-plugin-background-mode
https://github.com/Red-Folder/Cordova-Plugin-BackgroundService
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With