HTML5音频的onLoad [英] HTML5 Audio onLoad

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

问题描述

我怎样才能得到一个回调时,音频标签准备播放。 (告诉用户,实现我自己的控件时)

How can I get a callback when the audio tag is ready to play. (to tell the user, when implementing my own controls)

使用Chrome。

推荐答案

只是做这个视频元素上,但它应该用于音频工作。

Have only done this on the video element but it should work for audio.

首先,你不能绑定事件,我不知道为什么不起作用。所以,你必须使用的setTimeout。

Firstly, you can't bind the event, I don't know why that doesn't work. So you have to use setTimeout.

例如使用jQuery:

Example using jQuery:

$(function(){
    var audioReady = function(){
        if (youraudioelement.attr('readyState')) {
            alert("it's ready!");
        } else {
            setTimeout(audioReady, 250);
        }
    }
    audioReady();
}

更多信息: http://www.w3.org /TR/html5/video.html#the-ready-states

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

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