switch audio source with jquery and HTML5 audio tag

后端 未结 2 1428
广开言路
广开言路 2020-11-28 10:54

I have only found one other solution but it was incomplete so I need help here.

i have the audio set up:

相关标签:
2条回答
  • 2020-11-28 11:36

    You might also want to rename the function since 'change' is already a function in the jQuery universe.

    0 讨论(0)
  • 2020-11-28 11:38

    Your change function should be like this:

    function change(sourceUrl) {
        var audio = $("#player");      
        $("#ogg_src").attr("src", sourceUrl);
        /****************/
        audio[0].pause();
        audio[0].load();//suspends and restores all audio element
    
        //audio[0].play(); changed based on Sprachprofi's comment below
        audio[0].oncanplaythrough = audio[0].play();
        /****************/
    }
    

    The problems were audio.empty() and the audio var. You were attempting to append an emptied audio tag, and didn't write out the audio tag back to the browser.

    0 讨论(0)
提交回复
热议问题