Native Audio Problem

No idea, I am working from the docs here, but it probably doesn’t hurt if you unload something that isn’t even there, it just will not do anything and maybe go into the error callback (if you decide to handle that).

1 Like

For me this doesn’t work. doesn’t give any errors, just does produce any sound at all! I’m using the exact same code! Any ideas what might be off?

Me too, the native-audio plguin seems failing in iOS 10.

Here people said “using preloadComplex instead of preloadSimple” as a walk around https://github.com/floatinghotpot/cordova-plugin-nativeaudio/issues/100

I’m tried both on iOS11 and it doesn’t work. The only workaround I found was to load the audio file into memory, so that the App wouldn’t have to download it.

Hi @Sujan12!

Can I play audio from one page and stop from the same audio from another page. If yes please can you tell me how to do it?

Hi Dimitri can you show me an example of you preloading into memory mine is failing as well

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

    }

  }

}

and my app.component.ts

platform.ready().then(() => {

      platform.registerBackButtonAction(() => this.myHandlerFunction());

      StatusBar.hide();
      smartAudio.preload('menuSlide', 'assets/audio/menuSlide.wav');
      smartAudio.preload('onDrop', 'assets/audio/onDrop1.wav');
      smartAudio.preload('onPickUp', 'assets/audio/onPickUP1.wav');
      smartAudio.preload('onSwipe', 'assets/audio/onSlideGuess3.wav');
      smartAudio.preload('opponentAlert', 'assets/audio/opponentALert1.wav');
      smartAudio.preload('infoClick', 'assets/audio/onInfoClick.wav');
      smartAudio.preload('HomeChalkIntro', 'assets/audio/writing on chalkboard Intro.wav');
      smartAudio.preload('YouWonner', 'assets/audio/FunTime.wav');
      smartAudio.preload('tilesTumble', 'assets/audio/tilesTumble.wav');
      smartAudio.preload('challengerAlarm', 'assets/audio/alarma.wav');

    });
  }

I have follow this code on my app home.page.ts but it’s not work. It’s not play and not show any error. :cry: