I am trying to make run a background mode with Ionic, but when I am playing a song, and I enabled the Backgound Mode, the app crashes.
Actually, is posible make the background mode with Ionic?
This is my code:
import { Component } from '@angular/core';import {NavController} from '@ionic/angular';import {NativeAudio} from '@ionic-native/native-audio/ngx';import {BackgroundMode} from '@ionic-native/background-mode/ngx';@Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'],})export class HomePage { constructor(public navCtrl: NavController, public nativeAudio: NativeAudio , public backgroundMode: BackgroundMode) { this.nativeAudio.preloadSimple('audio1', 'assets/audio1.mp3').then((msg) => { console.log('message: '+ msg); }, (error) => { console.log('error: '+ error); }); } public playAudio(){ this.backgroundMode.enable(); this.backgroundMode.on('activate').subscribe(() => { this.nativeAudio.play('audio1'); }); this.nativeAudio.play('audio1', () => console.log('audio1 is done playing')); }}
This is my current config.
/bg-mode-example$ ionic infoIonic: Ionic CLI : 6.11.11 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.3.5 @angular-devkit/build-angular : 0.1000.8 @angular-devkit/schematics : 10.0.8 @angular/cli : 10.0.8 @ionic/angular-toolkit : 2.3.3Cordova: Cordova CLI : 10.0.0 Cordova Platforms : android 9.0.0 Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 6 other plugins)Utility: cordova-res (update available: 0.15.1) : 0.6.0 native-run (update available: 1.2.1) : 0.2.8System: Android SDK Tools : 26.1.1 (/home/gabriel/Android/Sdk) NodeJS : v10.19.0 (/usr/bin/node) npm : 6.14.8 OS : Linux 5.4
Addionationally, I have a gitlab repo https://gitlab.com/gabrielrincon/bgmode-testing/
What is wrong?
Thanks very much.