cordova-plugin-nativeaudio icon indicating copy to clipboard operation
cordova-plugin-nativeaudio copied to clipboard

preloadSimple not working, preloadComplex works fine

Open nitzanwilnai opened this issue 6 years ago • 1 comments

If I load my files using: window.plugins.NativeAudio.preloadSimple(url, prefix + url, successFunction, failFunction); It loads find, but sound does not play.

If I load my files using: window.plugins.NativeAudio.preloadComplex( url, prefix + url, 100, 1, 0, successFunction, failFunction ); Sounds plays fine.

nitzanwilnai avatar Mar 05 '18 20:03 nitzanwilnai

@nitzanwilnai any update on this ??

`import {Injectable} from "@angular/core"; import {Platform} from "ionic-angular"; import {NativeAudio} from "@ionic-native/native-audio";

@Injectable() export class SmartAudio {

audioType: string = 'html5'; sounds: any = [];

constructor(public nativeAudio: NativeAudio, platform: Platform) {

if (platform.is('cordova')) {
  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);

  let audio = {
    key: key,
    asset: key,
    type: 'native'
  };

  this.sounds.push(audio);
}

}

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);
  });

}

}

} `

darkthsideous avatar Sep 09 '18 00:09 darkthsideous