Audio playback via JavaScript for iPad EPUB -


i play audio in epub file ipad. audio should play , pause on click on image. image should change.

we use following js code saved 'audio-player.js'.

var channel_max = 12;   // number of channels audiochannels = new array(); (a=0;a<channel_max;a++) { // prepare channels     audiochannels[a] = new array();     audiochannels[a]['channel'] = new audio(); // create new audio object     audiochannels[a]['finished'] = -1; // expected end time channel } function play_multi_sound(s) {      (a=0;a<audiochannels.length;a++) {         thistime = new date();         if (audiochannels[a]['finished'] < thistime.gettime()) {            // 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 how can use it:

add audio player js file:

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

add audio tag body:

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

add image onclick event:

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

if want see real example, download "story wheel" (http://www.storywheelapp.com/) (free), create story, , email epub version of story created.

we releasing "auto play" version soon, should work bit better us. let me know think.

andy


Comments