开发者

Audio playback via JavaScript for iPad EPUB

开发者 https://www.devze.com 2023-03-02 00:14 出处:网络
I would like to play audio in my EPUB file for iPad. Audio should play and pause on click on an image.开发者_Python百科 The image should also change.We use the following JS code that we saved as \'aud

I would like to play audio in my EPUB file for iPad. Audio should play and pause on click on an image.开发者_Python百科 The image should also change.


We use the following JS code that we saved as 'audio-player.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;
        }
    }
}

Here is how you can use it:

Add the audio player js file:

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

Add an audio tag to the body:

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

Add an image with an onClick event:

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

If you want to see a real example, download "Story Wheel" (http://www.storywheelapp.com/) (free), create a story, and then email yourself an ePub version of the story you just created.

We will be releasing an "auto play" version soon, which should work a bit better for us. Let me know what you think.

Andy


Not sure about the image part. You can use and tags in EPUB for iPad. Some good information can be found in Liz Castro's blog.

0

精彩评论

暂无评论...
验证码 换一张
取 消