Problem with sound in loop


#1

Please help me! When i execute this funcion sound 3 times to fast, how to create delay beetween any sound in loop?

$scope.play_morse_code_from_tet = function(param){
var tekst = param;
var temp = 3;
var short = ‘/android_asset/www/audio/kropka.mp3’;
var long = ‘/android_asset/www/audio/kreska.mp3’;

function on(src){
 var my_media = new Media(src);
  my_media.play();
 }
function play_morse(){
  for(var i=0; i<=temp;i++){
    on(short);  
  }
  }
play_morse();

}


#2

use setTimeout function to add delay


#3

I have tried but doesnt work on real device


#4

Forget about media with HTML5! It is only buggy.

Have a look on http://ngcordova.com/docs/plugins/nativeAudio/
It solves many problems you’ll have with media playback on HTML5 level. If you want to mix sounds then use the complex loading routines.

It works on Android and iOS devices very well.

You’ll be more happier with native audio playback, trust me :slight_smile:


#5

Do you have any example? I need this for Morse Code.


#6

The link shows you a fully example. Where exactly do you need help? If you need to know, when a sound stops playing then look at the completeCallback parameter of the play method: https://github.com/driftyco/ng-cordova/blob/master/src/plugins/nativeAudio.js


#7
function on(src){
 var my_media = new Media(src);
  my_media.play();
 }
function play_morse(){
  for(var i=0; i<=temp;i++){
   $timeout(function() {
        on(short); 
   }, 1000); //delay of 1s 
  }
  }
play_morse();