HTML audio Element how to replay?

前端 未结 8 1760
自闭症患者
自闭症患者 2020-12-16 22:52

I setup a HTML5 page, that include a node. The page will to playing a music(mp3 format),but it just play sound to end, and I use javascript to control audio element,even so

8条回答
  •  不知归路
    2020-12-16 23:02

    If the server hosting the video does not support seeking on client (HTTP RangeRequest), the command

    audioElement.currentTime=0;
    

    from @JapanPro's answer is silently ignored in Chromium. This behavior is filled as crbug #121765.

    There is a handy guide on MDN how to configure your server to play nice. But if you cannot, I had success with doing

    audioElement.load();
    

    which unsurprisingly reloads the audio source and seeks to the start as a side effect. Not nice, but it is quite intuitive and it works.

    source: http://www.whatwg.org/specs/web-apps/current-work/#loading-the-media-resource

提交回复
热议问题