3 * Copyright (c) 2013, Intel Corporation.
5 * This program is licensed under the terms and conditions of the
6 * Apache License, version 2.0. The full text of the Apache License is at
7 * http://www.apache.org/licenses/LICENSE-2.0
11 VideoPlayer = function()
13 this.clearVideoTimeInterval = undefined;
14 this.loadPrevVideo = false;
15 this.currentVideoContent = undefined;
18 VideoPlayer.prototype.play = function()
20 console.log("MediaPlayer in VideoPlayer::play");
21 if (this.playerControls.paused)
23 this.playerControls.play();
25 //Start tracking the current time of the media. This is used to play from previous position on restart.
26 if (!this.content[this.listIndex].remoteFile)
28 var timeoutFunction = function()
30 localStorage.prevVideoTime = this.playerControls.currentTime;
33 //Start tracking the current time of the media. This is used to play from previous position on restart.
34 this.clearVideoTimeInterval = setInterval(timeoutFunction.bind(this),500);
39 VideoPlayer.prototype.pause = function()
41 if (!this.playerControls.paused)
43 this.playerControls.pause();
44 clearInterval(this.clearVideoTimeInterval);
48 VideoPlayer.prototype.playing = function()
50 return !(this.playerControls.paused);
53 VideoPlayer.prototype.next = function()
57 if (this.content.length > (this.listIndex + 1))
61 this.load(this.listIndex, false);
65 VideoPlayer.prototype.previous = function()
69 if (this.listIndex > 0 )
72 this.listIndex = this.content.length - 1;
74 this.load(this.listIndex, false);
78 VideoPlayer.prototype.load = function(index, play)
80 this.listIndex = index;
81 this.loadAndPlay = play;
82 this.playerControls.pause();
83 $("#videoSrc").attr("src", this.content[this.listIndex].contentURI);
84 this.playerControls.load();
87 VideoPlayer.prototype.videoLoaded = function()
89 this.currentVideoContent = this.content[this.listIndex];
91 //Only store track to localStorage if it's a local file, and current menu is the Video menu
92 if (!this.content[this.listIndex].remoteFile && localStorage.prevMenu === "mainVideoButton")
94 localStorage.prevVideo = this.content[this.listIndex].contentURI;
98 localStorage.prevVideo = undefined;
99 localStorage.prevVideoTime = undefined;
102 if (this.loadPrevVideo)
104 this.playerControls.currentTime = localStorage.prevVideoTime;
105 this.loadPrevVideo = false;
109 if (this.loadAndPlay)
112 this.currentFileLoaded = true;
115 VideoPlayer.prototype.onContentLoaded = function()
119 if (localStorage.prevVideo && localStorage.prevVideo !== "undefined")
121 for (var i = 0; i < this.content.length; i++)
123 if (this.content[i].contentURI === localStorage.prevVideo)
125 console.log("MediaPlayer: Previous video found, loading " + this.content[i].contentURI);
127 this.loadPrevVideo = true;
128 this.fillMediaList();
135 console.log("MediaPlayer: No previous video found, loading first");
142 console.log("MediaPlayer: Error when parsing videoContent");
146 VideoPlayer.prototype.makeListItem = function(j, k)
148 var canvasH = mediaListItemH * 0.95 ;
150 for (var i = j; (i < (j+k) && i < this.content.length); i++)
152 var artistText = {"text" : this.content[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0};
153 var trackText = {"text" : this.content[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0};
155 this.makeListBar(vidIcon, i, artistText, trackText);
157 // Set callback function for the new list item
158 $("#" + this.type + "CanvasNum" + i).click(function () {
161 videoPlayer.load($(this).parent().parent().index(), true);
162 $("#videoMediaList").hide();
166 console.log("MediaPlayer: load video error " + err.message);