Error playing audio file

I cannot figure out what is going on with my audio tag.

I have 2 different views for ionic with 2 different controllers, each with its own tag.

<audio controls="true">
  <source data-ng-src="{{getUrl()}}" type="audio/mpeg">
</audio>

      

They work flawlessly, but when I switch directly between viewAudio1 and viewAudio2, the sound tag won't play a good file, even if in dev tools the src doesn't match the file that plays the sound tag. I run this function to update the sound:

function loadAudio() {
  var audio = document.getElementsByTagName("audio")[0];
  document.getElementById('timeline').style.width = '0%';
  audio.setAttribute("src", $scope.getUrl());
  audio.pause();
  audio.load();
}

      

I've tried many questions to fix this with no luck.

+3


source to share


1 answer


Your variable audio

is local, so create this from the function as a global variable. Also, you now pause the new sound. Therefore, before uploading a new one, pause the old one.



0


source







All Articles