audio - ionic 2 how to play sound effects -


i'm developping application ionic 2 / angular2.

it's app learn english tenses runs sqlite database.

i add background sound plays in loop time.

the users can exercice quizz. play sound effects when user submit answer.

two different sounds : 1 , 1 bad answers.

i've tried nativeaudio, angular-audio , ionic audio modules each times documentation based on javascript , not typescript, or not helpfull.

with native audio, i've succeed once playing background sound after didn't work @ , came error : exception: uncaught (in promise): reference not exist specified audio id.

for other solutions (angular-audio , ionic-audio) either didn't how install either, once installed, had nothing : no sound , no error.

thank help.

install:

$ ionic plugin add --save cordova-plugin-nativeaudio $ npm install --save @ionic-native/native-audio 

usage:

import { nativeaudio } '@ionic-native/native-audio';  constructor(private nativeaudio: nativeaudio) { }  ...  this.nativeaudio.preloadsimple('uniqueid1', 'path/to/file.mp3').then(onsuccess, onerror); this.nativeaudio.preloadcomplex('uniqueid2', 'path/to/file2.mp3', 1, 1, 0).then(onsuccess, onerror);  this.nativeaudio.play('uniqueid1').then(onsuccess, onerror);  // can optionally pass callback called when file done playing this.nativeaudio.play('uniqueid1', () => console.log('uniqueid1 done playing')); 

reference: https://ionicframework.com/docs/native/native-audio/


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -