在客户端预加载音频文件以供后续使用

发布于 2024-08-31 22:41:55 字数 403 浏览 6 评论 0原文

我正在构建一个在线测试,该测试使用本机音频播放器(即非基于 Flash 的)实现音频 (mp3)。

该测试一次显示一个问题,并异步加载每个后续问题。

有些问题有附带的音频文件,有些则没有,并且音频文件的大小可能有几 MB。

因此,我希望做的是在测试开始时在客户端预加载音频文件,然后在出现相关问题时将它们移至适当位置。

到目前为止,我已经尝试将音频文件加载到 QuickTime 播放器中,然后当出现该问题时,我使用 jQuery 的 clone(true) 方法将其复制到显示的页面的一部分中。但是,当我执行此操作时,QuickTime 播放器必须从源重新加载音频文件。 Windows Media Player 也是如此。

有人对如何预加载音频客户端然后在需要时调用它有任何建议吗?

I'm building an online test which implements audio (mp3) using the native audio player (i.e. non Flash-based).

The test shows one question at a time and loads each subsequent question asynchronously.

Some questions have an accompanying audio file, others don't, and the audio files can be several MB in size.

So what I'm hoping to do is to preload the audio files client-side at the start of the test and then move these into place when the relevant question comes up.

So far I've tried loading an audio file into a QuickTime player, then when that question comes up I use jQuery's clone(true) method to copy this into a part of the page which is displayed. However, when I do this the QuickTime player has to reload the audio file from source. Same is true for Windows Media Player.

Does anyone have any suggestions as to how I can preload the audio client-side and then call it forward when needed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南七夏 2024-09-07 22:41:55

我认为你需要做的是得到像 jPlayersoundmanager 然后像这样的ajax函数来预加载音频:

$(document).ready(function() {
    $.ajax({
        url: "soundfile.mp3",
        success: function() {
            $("#play_button").show();
        }
    });
});

what you need to do I think is to get your hands on something like jPlayer or soundmanager and then ajax function like this to preload the audio:

$(document).ready(function() {
    $.ajax({
        url: "soundfile.mp3",
        success: function() {
            $("#play_button").show();
        }
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文