Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preloadSimple not working, preloadComplex works fine #149

Open
nitzanwilnai opened this issue Mar 5, 2018 · 1 comment
Open

preloadSimple not working, preloadComplex works fine #149

nitzanwilnai opened this issue Mar 5, 2018 · 1 comment

Comments

@nitzanwilnai
Copy link

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.

@darkthsideous
Copy link

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

}

}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants