停止html5音频 [英] stopping html5 audio

查看:112
本文介绍了停止html5音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个函数来停止在DOM中播放html5音频的所有实例?

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

html5 audio

html5 audio

<audio class="AudioPlayerV1" preload="none" width="292">
    <source src="test.mp3" type="audio/mpeg" />
</audio>

js

AudioPlayerV1('*').each(function() {
    this.setStop();
});


推荐答案

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

这只是找到所有< audio> DOM中的元素,并使用标准API暂停每个元素的播放。

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

这里有一些关于< audio> < video> 标签: https ://developer.mozilla.org/en/Using_HTML5_audio_and_video

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

AudioPlayerV1 脚本说明这是暂停< audio> 元素的方式:

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

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

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

看起来应该在选择的DOM元素上调用 AudioPlayerV1 插件( s)并传入一个选项。

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

运行插件暂停多个< audio> 你应该能够做到的元素:

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

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

选择< audio> 元素在DOM中并将它们传递给 AudioPlayerV1 插件。应该编写插件来处理这个,但如果不是,那么你必须在每个元素上调用插件。在循环中最简单:

Which selects the <audio> 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');
});

这篇关于停止html5音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆