Booklet.js
Summary
No overview generated for 'Booklet.js'
|
Method Summary
|
static void
|
init()
|
var bookletController = new TKObject();
bookletController.init = function () {
this.playbackHasStarted = false;
window.iTunes.stop();
this.startAudioLoop();
if (appData.feature.XID){
var feature = this.getTrack(appData.feature);
if (feature && feature.bookmark != 0){
this.playbackHasStarted = true;
this.dispatchDisplayUpdates();
}
}
window.addEventListener("play", this, false);
window.addEventListener("pause", this, false);
window.addEventListener("videoclosed", this, false);
this.navigation = new TKNavigationController({
id : 'navigation',
rootController : homeController,
delegate : this
});
};
bookletController.handleEvent = function(event) {
switch (event.type) {
case "play":
this.stopAudioLoop();
break;
case "pause":
break;
case "videoclosed":
this.startAudioLoop();
this.dispatchDisplayUpdates();
debug(iTunes.currentChapter);
break;
default:
debug("Unknown event type in bookletController : " + event.type);
}
};
bookletController.startAudioLoop = function() {
if (this.audioLoop && appData.audioLoop && !appData.audioLoop.loop) {
this.audioLoop.pause();
this.audioLoop.volume = 0;
return;
}
if (appData.audioLoop && !this.audioLoop) {
this.audioLoop = new Audio();
this.audioLoop.src = appData.audioLoop.src;
this.audioLoop.style.display = "none";
document.body.appendChild(this.audioLoop);
this.audioLoop.volume = 0;
}
if (this.audioLoop) {
this.audioLoop.loop = appData.audioLoop.loop;
this.audioLoop.volume = Math.min(1, window.iTunes.volume);
this.audioLoop.play();
}
};
bookletController.stopAudioLoop = function() {
if (this.audioLoop) {
this.audioLoop.pause();
this.audioLoop.loop = false;
this.audioLoop.currentTime = 0;
}
};
bookletController.play = function (trackObj) {
var track = this.getTrack(trackObj);
if (track != null){
track.play();
}
};
bookletController.playFeature = function (){
var feature = bookletController.getTrack(appData.feature);
if (feature != null){
feature.play();
if (!this.playbackHasStarted){
this.playbackHasStarted = true;
}
}
};
bookletController.resumeFeature = function(){
bookletController.playFeature();
};
bookletController.playChapter = function (index){
var feature = this.getTrack(appData.feature);
if (feature != null){
feature.play({startChapterIndex : index});
if (!this.playbackHasStarted){
this.playbackHasStarted = true;
}
}
};
bookletController.getChapter = function (){
var feature = this.getTrack(appData.feature);
if (feature){
if (iTunes.currentChapter == 0 && feature.bookmark != 0){
debug("estimating");
var estimatedChapter = Math.floor((feature.bookmark / feature.duration) * feature.chapters.length);
var actualChapter = -1;
if ((feature.chapters[estimatedChapter].startOffsetTime / 1000) == feature.bookmark){
} else if ((feature.chapters[estimatedChapter].startOffsetTime / 1000) < feature.bookmark){
while (estimatedChapter < feature.chapters.length && (feature.chapters[estimatedChapter].startOffsetTime / 1000) < feature.bookmark){
estimatedChapter++;
}
} else if ((feature.chapters[estimatedChapter].startOffsetTime / 1000) > feature.bookmark){
while (estimatedChapter >= 0 && (feature.chapters[estimatedChapter].startOffsetTime / 1000) > feature.bookmark){
estimatedChapter--;
}
}
actualChapter = estimatedChapter;
return actualChapter;
} else {
debug("itunes query");
return iTunes.currentChapter;
}
} else {
return -1;
}
}
bookletController.buildPlaylist = function (tracks){
var tracklistObj = iTunes.createTempPlaylist();
var tracklist = [];
for (var i = 0; i < tracks.length; i++){
var track = this.getTrack(tracks[i]);
if (track != null){
tracklist.push(track);
}
}
tracklistObj.addTracks(tracklist);
debug("added " + tracklist.length + " of " + tracks.length + " tracks successfully.");
return tracklistObj;
};
bookletController.buildNonLibraryPlaylist = function (tracks){
var tracklistObj = iTunes.createTempPlaylist();
var tracklist = [];
for (var i = 0; i < tracks.length; i++){
var track = {};
track.url = tracks[i].src;
track.title = tracks[i].string;
track.artist = appData.feature.artist;
track.album = appData.feature.title;
debug("adding: " + track.title + " (" + track.url + ")");
tracklist.push(track);
}
debug("pushing to tracklistOb");
tracklistObj.addURLs(tracklist);
return tracklistObj;
};
bookletController.trackDuration = function (trackObj){
var track = this.getTrack(trackObj);
if (track != null){
debug("querying duration");
return track.durationAsString;
} else {
return "0:00";
}
};
bookletController.trackNumber = function (trackObj){
var track = this.getTrack(trackObj);
if (track != null){
debug("querying track number");
return track.trackNumber;
} else {
return "0";
}
};
bookletController.getTrack = function (trackObj){
if (trackObj.XID){
debug("searching by XID: " + trackObj.XID);
var iTunesTrack = window.iTunes.findTracksByXID(trackObj.XID);
if (iTunesTrack.length > 0){
debug("found by XID");
return iTunesTrack[0];
} else {
debug("XID not found in library");
return null;
}
} else {
debug("no XID");
return null;
}
};
bookletController.playNonLibraryContent = function (trackObj){
debug("videos/" + trackObj.src);
debug({title : trackObj.string, artist : appData.feature.artist, album : appData.feature.title});
window.iTunes.play("videos/" + trackObj.src, {title : trackObj.string, artist : appData.feature.artist, album : appData.feature.title});
};
bookletController.childControllers = [];
bookletController.registerForDisplayUpdates = function (childController) {
if (this.childControllers.indexOf(childController) == -1) {
this.childControllers.push(childController);
}
};
bookletController.dispatchDisplayUpdates = function () {
for (var i=0; i < this.childControllers.length; i++) {
if (TKUtils.objectIsFunction(this.childControllers[i].updateDisplay)) {
this.childControllers[i].updateDisplay();
}
}
};
var iTunesEmulator = {
volume : 1,
platform : 'Emulator',
version : '-1'
};
iTunesEmulator.play = function (mediaLocation) {
debug("iTunesEmulator - play: " + mediaLocation);
};
iTunesEmulator.stop = function () {
debug("iTunesEmulator - stop");
};
iTunesEmulator.findTracksByStoreID = function (storeID) {
debug("iTunesEmulator - findTracksByStoreID: " + storeID);
return [new ITunesTrackEmulator()];
};
iTunesEmulator.findTracksByXID = function (xID) {
debug("iTunesEmulator - findTracksByXID: " + xID);
return [new ITunesTrackEmulator()];
};
function ITunesTrackEmulator() {
}
ITunesTrackEmulator.prototype.play = function (params) {
debug("iTunesTrackEmulator - play: " + params);
var event = document.createEvent("HTMLEvents");
event.initEvent("play", false, false);
window.dispatchEvent(event);
setTimeout(function() {
debug("iTunesTrackEmulator - coming back from playback");
event = document.createEvent("HTMLEvents");
event.initEvent("videoclosed", false, false);
window.dispatchEvent(event);
}, 5000);
};
var SUPPORTS_KEYBOARD_NAVIGATION;
function init () {
document.onselectstart = function() { return false; };
if (!window.iTunes) {
window.iTunes = iTunesEmulator;
}
SUPPORTS_KEYBOARD_NAVIGATION = (parseInt(window.iTunes.version, 0) < 9);
bookletController.init();
};
window.addEventListener('load', init, false);
Documentation generated by
JSDoc on Tue Sep 15 21:24:36 2009