I am using below code to load my mp3 files
this.nativeAudio.preloadSimple(‘sound2’, ‘assets/sound2.mp3’.then(() => {
console.log(‘preload success’)
}, (err) => {
console.log(err);
});
However i get a error when preload the mp3 java.io.FileNotFoundException: www/assets/sound2.mp3
I am sure the sound2.mp3 is placed in both /src/assets/sound2.mp3
and www/assets/sound2.mp3
Anyone got any ideas on it?
did you find any solution im also facing this issue
No i don’t. But now i use the html audio to play sound
private audioPlayer: HTMLAudioElement = new Audio();
how you used this html audio element please share that code with us
A simple solution would be to use native Audio.
in-your-typescript-component.html
// define the audio variable
let audio: HTMLAudioElement = new Audio();
constructor() {
this.initAudio();
}
public playAudio() {
this.audio.play();
}
public pauseAudio() {
this.audio.pause();
}
public stopAudio(){
this.audio.pause();
this.audio.currentTime = 0;
}
private initAudio(){
this.audio.src = `/assets/audio/sample1.mp3`;
this.audio.load();
}
in-your-html-component.html
<button (click)="playAudio()">Play</button>
<button (click)="pauseAudio()">Pause</button>
<button (click)="stopAudio()">Stop</button>
1 Like
@vestemeansorin91 did you tested this is the native app? Does it work?
DzCorps
November 21, 2021, 9:51pm
7
CAPACITOR
go to:
/node_modules/cordova-plugin-nativeaudio/src/android/NativeAudio.java
then: change the code line
String fullPath = "www/".concat(assetPath)
to
String fullPath = "public/".concat(assetPath);