如何提高音频加载速度使用JavaScript? [英] How to increase audio loading speed using JavaScript?

查看:171
本文介绍了如何提高音频加载速度使用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了code播放使用JavaScript的 .MP3 文件。但该文件正在采取太多的时间来在Android上玩。我想点击的文本图像上后快速播放声音。如何提高加载速度在Android?

I have created code for playing an .mp3 file using JavaScript. But the file is taking to much time to play on Android. I want to play the sound quickly after click on a text image. How do I increase loading speed on Android?

我的JavaScript code:

My JavaScript code:

if(window.audio) 
{
    audio.pause(); 
}
window.audio = new Audio (audio_path);
window.audio.play();

检查演示在这里 -
http://97.74.195.122/gizmo-demo/canvasslidertwo.php

在上面的链接,点击日语单词播放声音。

In the above link, click on the Japanese word for playing sound.

推荐答案

您实际上面临着描绘的错误 这个问题 。这使得Chrome浏览器,从音频元素每次更改它的src属性(无缓存)重新下载时的文件。

You are actually facing the bug depicted in this question. Which makes chrome browsers redownload the files from an Audio Element each time you change its src property (no-caching).

一个解决方案是使用 WebAudioAPI 和存储您的音频文件在缓冲区中。这样做,你应该能够给他们打电话,没有延迟。
您可以检查接受的答案关于如何处理它的例子。

One solution would be to use the WebAudioAPIand store your audio files in the buffer. Doing so, you should be able to call them with no latency. You can check the accepted answer for an example on how to deal with it.

或者你也可以尝试不叫每次点击一个新的音频(),和而每一个音频从页面加载,只有在调用它们的播放()方法单击。
但我不知道它会解决您的问题。

Or you could also try not to call a new Audio() on each click, and rather load every audios from your page and only call their play() method on click. But I'm not sure it would fix your issue.

这篇关于如何提高音频加载速度使用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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