简体   繁体   English

音频播放错误的文件

[英]Audio play wrong file

I can't figure out what's going on with my audio tag. 我无法弄清楚我的音频标签发生了什么。

i've 2 different view on ionic with 2 different controller each one have it's own audio tag. 我有2个不同的离子视图,2个不同的控制器,每个都有自己的音频标签。

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

They work perfecly but when i switch directly between viewAudio1 and viewAudio2 the audio tag won't play the good file even so in dev tools the src don't match the file that the audio tag is playing. 它们完美地工作但是当我直接在viewAudio1和viewAudio2之间切换时,音频标签将不会播放好文件,即使在开发工具中,src与音频标签正在播放的文件不匹配。 I fire this function to update the audio: 我启动此功能来更新音频:

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 try many tings to fix this with no luck. 我尝试了许多铃声以解决这个问题而没有运气。

Your audio variable is local, so create that out of the function as a global variable. 您的audio变量是本地的,因此将该函数创建为全局变量。 Moreover you pause the new audio now. 此外,您现在暂停新音频。 So before loading a new, pause the old one. 所以在加载新的之前,暂停旧的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM