gpt4 book ai didi

javascript - 通过 JavaScript 为 iPad EPUB 播放音频

转载 作者:行者123 更新时间:2023-11-30 10:50:14 25 4
gpt4 key购买 nike

我想在我的 iPad 版 EPUB 文件中播放音频。单击图像时应播放和暂停音频。图像也应该改变。

最佳答案

我们使用以下保存为“audio-player.js”的 JS 代码。

var channel_max = 12;   // number of channels
audiochannels = new Array();
for (a=0;a<channel_max;a++) { // prepare the channels
audiochannels[a] = new Array();
audiochannels[a]['channel'] = new Audio(); // create a new audio object
audiochannels[a]['finished'] = -1; // expected end time for this channel
}
function play_multi_sound(s) {

for (a=0;a<audiochannels.length;a++) {
thistime = new Date();
if (audiochannels[a]['finished'] < thistime.getTime()) { // is this channel finished?
audiochannels[a]['finished'] = thistime.getTime() + document.getElementById(s).duration*1000;
audiochannels[a]['channel'].src = document.getElementById(s).src;
audiochannels[a]['channel'].load();
audiochannels[a]['channel'].play();
break;
}
}
}

这里是你如何使用它:

添加音频播放器js文件:

<script src="../js/audio-player.js" type="text/javascript"/>

在正文中添加音频标签:

<audio id="storyAudio1" preload="auto" src="../audio/page_1.caf"/>

添加带有 onClick 事件的图像:

<img src="../images/play-button.png" class="audioButton"
onclick="play_multi_sound('storyAudio1')"/>

如果您想查看真实示例,请下载“Story Wheel”(http://www.storywheelapp.com/)(免费),创建一个故事,然后将您刚创建的故事的 ePub 版本通过电子邮件发送给自己.

我们将很快发布“自动播放”版本,这对我们来说应该会更好一些。让我知道你的想法。

安迪

关于javascript - 通过 JavaScript 为 iPad EPUB 播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5843643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com