Can some body help me with this, i have a list of cards when i click on the card the first time, i dont get any sound, and the following error is poped up, then when i click it again i get a sound, im using NativeAudio
import { Component } from '@angular/core';
import { NavController, IonicPage } from 'ionic-angular';
import { NativeAudio } from '@ionic-native/native-audio';
// import { Media, MediaObject } from '@ionic-native/media';
@IonicPage()
@Component({
selector: 'page-card-background',
templateUrl: 'card-background.html'
})
export class CardBackgroundPage {
NativeAudio: any;
sounds: any = [];
cards = [
{
imageUrl: 'assets/img/card/cat-2204851_1920.jpg',
title: 'Meow!',
url: 'assets/audio/meow.wav'
},
{
imageUrl: 'assets/img/card/cat-1992140_1920.jpg',
title: 'Kitten',
url: 'assets/audio/kitten2.wav'
},
{
imageUrl: 'assets/img/card/cat-1333926_1920.jpg',
title: 'Funny',
url: 'assets/audio/meow.wav'
},
{
imageUrl: 'assets/img/card/cat-334383_1920.jpg',
title: 'Angry',
url: 'assets/audio/Angry-cat-sound.wav'
},
{
imageUrl: 'assets/img/card/pexels-photo-538628.jpeg',
title: 'Purring',
url: 'assets/audio/Purring-SoundBible.com-1561515931.wav'
}];
constructor(public navCtrl: NavController, private nativeAudio: NativeAudio) {
}
cardTapped(card) {
console.log(card.url);
this.nativeAudio.preloadSimple('newOder', card.url).then(() => {
}).catch((err) => {
console.log(err);
});
this.nativeAudio.play('newOder', () => {
console.log("iim in the callback")
this.nativeAudio.stop('newOder');
this.nativeAudio.unload('newOder');
console.log("unloaded!");
});
};
}
heres the error log
[18:08:27] console.log: Ionic Native: deviceready event fired after 4627 ms
[18:09:23] console.log: assets/audio/meow.wav
[18:09:23] console.error: Unhandled Promise rejection: A reference does not exist for the specified audio id. ; Zone:
; Task: null ; Value: A reference does not exist for the specified audio id. null
[18:09:25] console.log: assets/audio/kitten2.wav
[18:09:25] console.log: A reference already exists for the specified audio id.
[18:09:27] console.log: iim in the callback
[18:09:27] console.log: unloaded!
my goal is to click one time and get the sound directly rather then tapping twice