stopping html5 audio

前端 未结 3 1262
借酒劲吻你
借酒劲吻你 2021-01-21 23:41

How would I write a function that stops ALL instances of playing html5 audio in the DOM?

html5 audio

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 23:58

    $.each($('audio'), function () {
        this.pause();
    });
    

    This just finds all the elements in the DOM and uses the standard API to pause the playback for each.

    Here's some excellent reading about and tags: https://developer.mozilla.org/en/Using_HTML5_audio_and_video

    Update

    The documentation for the AudioPlayerV1 script states this is how you pause an element:

    $('#audio_id').AudioPlayerV1('pause');
    

    Source: http://1.s3.envato.com/files/14653378/index.html#how-to-use

    It looks like the AudioPlayerV1 plugin is supposed to be called on a selection of DOM element(s) and passed in an option.

    Update

    To run the plugin to pause multiple elements you should be able to do this:

    $('audio').AudioPlayerV1('pause');
    

    Which selects the elements in the DOM and passes them to the AudioPlayerV1 plugin. the plugin should be written to handle this but if it isn't then you have to call the plugin on each element. Inside a loop would be easiest:

    $.each($('audio'), function () {
        $(this).AudioPlayerV1('pause');
    });
    

提交回复
热议问题