change <audio> src with javascript

后端 未结 6 1623
离开以前
离开以前 2020-11-27 04:52

I have multiple audio files that I want to stream based on the user selects. How do I do that? This is what I have so far and it doesn\'t seem to work.

*UPDATE: Mad

6条回答
  •  旧时难觅i
    2020-11-27 05:20

    If you are storing metadata in a tag use data attributes eg.

  • Now use the attribute to get the name of the song

    var audio = document.getElementById('audio');
    audio.src='audio/ogg/' + document.getElementById('song1').getAttribute('data-value');
    audio.load();
    

提交回复
热议问题