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)
111 var canvasW = mediaListItemW;
112 var canvasH = mediaListItemH * 0.95 ;
116 lightColor = "lightColor ";
121 this.mediaListItems.append("<li id=" + this.type + "ListItem" + i + " style='width:" + mediaListItemW + "px;" + " height:" + mediaListItemH + "px;" +
122 " margin-bottom: 10px' ><a href='#' class='" + lightColor + "night' >" +
123 "<canvas id=" + this.type + "CanvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
129 this.mediaListItems.append("<li id=" + this.type + "ListItem" + i + " style='width:" + mediaListItemW + "px;" + " height:" + mediaListItemH + "px;" +
130 " margin-bottom: 10px' ><a href='#' class='" + lightColor + "night' >" +
131 "<canvas id=" + this.type + "CanvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
138 var currentCanvas = document.getElementById(this.type + "CanvasNum" + i);
139 var currentCTX = currentCanvas.getContext("2d");
141 this.content[i].ctx = currentCTX;
143 currentCTX.drawImage(icon, 0, 0, canvasH, canvasH );
144 var artistText = new TextObject(currentCTX,artistTextObj);
145 var trackText = new TextObject(currentCTX,trackTextObj);
146 var mediaTextTemp1 = screenOrientation === "portrait" ? mediaTextTemplate2 : mediaTextTemplate2Landscape;
147 var mediaTextTemp2 = screenOrientation === "portrait" ? mediaTextTemplate3 : mediaTextTemplate3Landscape;
148 var trackTextTemp = screenOrientation === "portrait" ? trackTextTemplate : trackTextTemplateLandscape;
150 trackText.applyTemplate(mediaTextTemp1);
152 trackText.applyTemplate(mediaTextTemp2);
154 artistText.applyTemplate(trackTextTemp);
155 artistText.drawObj();
159 console.log("MediaPlayer: drawImage failed for " + this.type + " - reason -> " + err);
163 MediaPlayer.prototype.fillMediaList = function()
165 console.log("MediaPlayer in fillMediaList for content = " + this.type);
166 this.fillingList = true;
168 //Don't try and fill an empty content list
169 if (this.content === undefined || this.content === null || this.content.length <=0)
172 this.emptyTimeouts();
174 this.mediaListItems.empty();
180 audioMediaListLoaded = true;
183 videoMediaListLoaded = true;
186 imageMediaListLoaded = true;
195 for (var i=0; i < this.content.length; i++)
197 tmpClearTimeout = setTimeout(this.makeListItem.bind(this, i, jumpSize), timeOut);
198 this.clearDrawTimeouts.push(tmpClearTimeout);