2 * Copyright (c) 2013, Intel Corporation.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 MediaPlayer = function(type)
13 this.content = new Array();
14 this.mediaList = $("#" + type + "MediaList");
15 this.mediaListItems = $("#" + type + "MediaListItems");
16 this.playerControls = undefined;
17 this.mediaListLoaded = false;
19 this.imagesLoaded = false;
20 this.loadAndPlay = false;
21 this.loadPrev = false;
22 this.currentFileLoaded = false;
23 this.fillingList = false;
24 this.clearDrawTimeouts = new Array();
29 console.log("MediaPlayer creating AudioPlayer");
30 audioPlayer = new AudioPlayer;
31 $.extend(this, audioPlayer);
32 this.playerControls = document.getElementById("audioPlayer");
35 console.log("MediaPlayer creating VideoPlayer");
36 videoPlayer = new VideoPlayer;
37 $.extend(this, videoPlayer);
38 this.playerControls = document.getElementById("videoPlayer");
41 console.log("MediaPlayer creating ImagePlayer");
42 imagePlayer = new ImagePlayer;
43 $.extend(this, imagePlayer);
44 this.playerControls = new ImageControls();
47 console.log("MediaPlayer: Trying to make an invalid player type " + type);
52 MediaPlayer.prototype.updateContent = function(newContent, append)
54 console.log("MediaPlayer: updating content for " + this.type);
55 if (newContent && newContent !== undefined && newContent.length > 0)
59 this.content = this.content.concat(newContent);
63 this.content.length = 0;
64 this.content = newContent;
68 console.log("MediaPlayer: invalid content update for " + this.type);
71 MediaPlayer.prototype.getContent = function()
76 MediaPlayer.prototype.contentLength = function()
78 return this.content.length;
81 MediaPlayer.prototype.show = function()
83 $("#" + this.type + "Player").show();
86 MediaPlayer.prototype.clearContent = function()
88 console.log("MediaPlayer: clearing content for " + this.type);
90 this.content.length = 0;
93 MediaPlayer.prototype.currentIndex = function()
95 return this.listIndex;
98 MediaPlayer.prototype.emptyTimeouts = function()
102 while (clearItem = this.clearDrawTimeouts.pop())
104 clearTimeout(clearItem);
108 MediaPlayer.prototype.makeListBar = function(icon, i, artistTextObj, trackTextObj)
110 var lightColor = (i+1)%2 !== 0 ? "lightColor " : "";
111 var nightColor = nightMode ? "night" : "";
112 var canvasW = Math.floor(mediaListItemW);
113 var canvasH = Math.floor(mediaListItemH * 0.95) ;
115 this.mediaListItems.append("<li id=" + this.type + "ListItem" + i + " style='width:" + mediaListItemW + "px;" + " height:" + mediaListItemH + "px;" +
116 " margin-bottom: 10px' ><a href='#' class='" + lightColor + nightColor + "' >" +
117 "<canvas id=" + this.type + "CanvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
123 var currentCanvas = document.getElementById(this.type + "CanvasNum" + i);
124 var currentCTX = currentCanvas.getContext("2d");
126 if (currentCanvas && currentCTX)
128 this.content[i].ctx = currentCTX;
130 currentCTX.drawImage(icon, 0, 0, canvasH, canvasH );
131 var artistText = new TextObject(currentCTX,artistTextObj);
132 var trackText = new TextObject(currentCTX,trackTextObj);
133 var trackTextTemp1 = screenOrientation === "portrait" ? mediaTextTemplate2 : mediaTextTemplate2Landscape;
134 var trackTextTemp2 = screenOrientation === "portrait" ? mediaTextTemplate3 : mediaTextTemplate3Landscape;
135 var artistTextTemp = screenOrientation === "portrait" ? trackTextTemplate : trackTextTemplateLandscape;
137 trackText.applyTemplate(trackTextTemp1);
139 trackText.applyTemplate(trackTextTemp2);
141 artistText.applyTemplate(artistTextTemp);
142 artistText.drawObj();
145 console.log("MediaPlayer: Failed to draw media item for index " + i );
149 console.log("MediaPlayer: drawImage failed for " + this.type + " - reason -> " + err);
150 console.log("Source below");
151 console.log("Src = " + icon.src);
155 MediaPlayer.prototype.fillMediaList = function()
157 console.log("MediaPlayer in fillMediaList for content = " + this.type);
158 this.fillingList = true;
160 //Don't try and fill an empty content list
161 if (this.content === undefined || this.content === null || this.content.length <=0)
164 this.emptyTimeouts();
166 this.mediaListItems.empty();
172 audioMediaListLoaded = true;
175 videoMediaListLoaded = true;
178 imageMediaListLoaded = true;
187 for (var i=0; i < this.content.length; i++)
189 tmpClearTimeout = setTimeout(this.makeListItem.bind(this, i, jumpSize), timeOut);
190 this.clearDrawTimeouts.push(tmpClearTimeout);