HTML5音频加载时间/元数据而不是音频? [英] html5 load audio time/metadata but not audio?

查看:307
本文介绍了HTML5音频加载时间/元数据而不是音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很坚持。我这个搞砸了至少30分钟,我无法弄清楚如何$仅限于P $ PLOAD元。

如果你去这里你会看到有一个preLOAD属性,允许你指定什么preLOAD。我将其标记下来只是因为我想让每一个的AudioFile的时间长度为元数据。既然不装我试过 .load()和加载,即使我指定的元数据的实际声音。

我如何加载HTML5的javascript元?如果它加载第二个或两个音频的我不会心态,只要它是不是要preLOAD分钟或整个文件。

http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-networkstate

值2 = NETWORK_LOADING,其中1 =空闲又名加载。

http://jsfiddle.net/CD3BZ/

 <身体GT;
< D​​IV>点击测试是否加载< / DIV><脚本类型=文/ JavaScript的SRC =htt​​p://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js>< / SCRIPT>
<脚本类型=文/ JavaScript的字符集=utf-8>
尝试{
    VAR A1 =新Audio('http://freshly-ground.com/data/audio/sm2/20060924%20-%20Ghosts%20&%20Goblins%20Reconstructed.ogg');
    $(A1).bind('等待load​​edmetadata',函数(E){
        //警报('A1'+ a1.duration +''+ a1.networkState);
    });    $(A1).bind('canplay',函数(E){
        警报('a1z'+''+ a1.networkState);
    });    $(A1).attr('preLOAD','元数据');
    A1 preLOAD ='元'。
    //alert(a1.duration);
    //a1.play();
    a1.load();
    $('格')。点击(函数(五){
        警报('a1z'+''+ a1.networkState);
    });
}
赶上(E){
    警报(E);
}
< / SCRIPT>< /身体GT;


解决方案

的可以使用preLOAD属性:

 <音频自动缓冲preLOAD =元数据SRC =audio.foo>< /音频>

还有一个建议和的克里斯·皮尔斯的博客,这基本上意味着暂停,然后设置SRC为空字符串。正如上发表评论解释说,这种方法是不理想的...你可以(在理论上)做这个只要等待load​​edmetadata事件解雇,并且您检索您需要的元数据。

这个问题建议设置页眉,这也可能工作...

I am very stuck. I messed with this for at least 30mins and I can't figure out how to preload metadata only.

if you go here you'll see there is a preload attribute that allows you to specify what to preload. I marked it down as metadata only because I wanted the time length of every audiofile. Since it wasn't loading I tried .load() and that loads the actual audio even though I specified metadata.

How do I load the meta in html5 javascript? if it loaded a second or two of audio I wont mind as long as it isn't trying to preload minutes or the whole file.

http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-networkstate

Value 2 = NETWORK_LOADING, where 1 = idle aka loaded.

http://jsfiddle.net/CD3BZ/

<body>
<div>Click to test if loaded</div>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
try{
    var a1 = new Audio('http://freshly-ground.com/data/audio/sm2/20060924%20-%20Ghosts%20&%20Goblins%20Reconstructed.ogg');
    $(a1).bind('loadedmetadata', function(e){
        //alert('a1 ' + a1.duration + ' ' + a1.networkState);
    });

    $(a1).bind('canplay', function(e){
        alert('a1z ' + ' ' + a1.networkState);
    });

    $(a1).attr('preload', 'metadata');
    a1.preload = 'metadata';
    //alert(a1.duration);
    //a1.play();
    a1.load();
    $('div').click(function(e){
        alert('a1z ' + ' ' + a1.networkState);
    });
}
catch(e){
    alert(e);
}
</script>

</body>

解决方案

You should be able to use the preload attribute:

<audio autobuffer preload="metadata" src="audio.foo"></audio>

There's also a suggestion and some discussion on Chris Pearce's blog, which basically suggests pausing and then setting src to an empty string. As explained in comments on the post, this method is not ideal... You could (in theory) do this as soon as the loadedmetadata event has fired, and you've retrieved the metadata you need.

This question suggest setting headers, which also might work...

这篇关于HTML5音频加载时间/元数据而不是音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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