@orzel71 wrote:
Hi Folks,
I’m new here.
Ionic is a great framework and I really enjoy it.
One thing deosn’t work for me, and I tried a lot of workarounds, unfortunately still not resolved.
NativeAudio play’s sounds in the test environment(browser) very well.
After creating debug file for android , copy package on the device , executing, no sound audible?
Any Idea??
My Code:
Service:
import { Injectable } from ‘@angular/core’;
import { Platform } from ‘ionic-angular’;
import { NativeAudio } from ‘@ionic-native/native-audio’;/*
Generated class for the SmartAudioProvider provider.See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI.
*/
@Injectable()
export class SmartAudio {audioType: string = ‘html5’;
sounds: any = [];constructor(public nativeAudio: NativeAudio, platform: Platform) {
if(platform.is('cordova')){ this.audioType = 'native'; } if(platform.is('android')){ this.audioType = 'native'; }
}
preload(key, asset) {
if(this.audioType === 'html5'){ let audio = { key: key, asset: asset, type: 'html5' }; this.sounds.push(audio); } else { //this.nativeAudio.preloadSimple(key, asset); this.nativeAudio.preloadComplex(key, asset,1,1,0).then(onSuccess=>{ let audio = { key: key, //asset: key, asset: asset, type: 'native' }; this.sounds.push(audio); },onError=>{} ); }
}
onSuccess()
{}
play(key){
let audio = this.sounds.find((sound) => { return sound.key === key; }); if(audio.type === 'html5'){ let audioAsset = new Audio(audio.asset); audioAsset.play(); } else {
/*
this.nativeAudio.play(audio.asset).then((res) => {
console.log(res);
}, (err) => {
console.log(err);
});
*/this.nativeAudio.play(audio.key).then((res) => { console.log(res); }, (err) => { console.log(err); }); }
}
}
App:
//app.component
initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleDefault();
this.splashScreen.hide();
this.smartAudio.preload(‘horn’, ‘assets/sounds/horn.mp3’);this.smartAudio.preload('error', 'assets/sounds/Fehler.wav'); this.smartAudio.preload('ok', 'assets/sounds/Gut.wav'); });
in page:
playAudio(found:boolean) {if ( found )
this.smartAudio.play(‘ok’);
else
this.smartAudio.play(‘error’);}
Thesounds files are stored in /assets/sounds
Posts: 1
Participants: 1