var iconWidth;
var padding;
var contentType = "AUDIO";
-var audioContent;
-var videoContent;
-var imageContent;
-var currentContent;
var currentPlayer;
-var currentPlayerType = "AUDIO";
-var currentPlayerControls;
+var currentMediaList = $("#audioMediaList");
+var audioMediaListLoaded = false;
+var videoMediaListLoaded = false;
+var imageMediaListLoaded = false;
var audioPlayer;
var videoPlayer;
-var listIndex = 0;
-var videoIndex = 0;
-var imageIndex = 0;
+var imagePlayer;
var vidIcon = new Image();
var imgIcon = new Image();
var musicIcon = new Image();
var imagesLoaded = false;
var mediaListItemW;
var mediaListItemH;
-var imageControls;
-
+var playOnConnect = false;
var mediaNameCanvas;
var mediaNameCTX;
+var trackTimeCanvas;
+var trackTimeCTX;
+var speechObj;
+var nightMode = false;
+var waitingToResumeVideo = false; //Media has been paused by exterior forces. If set to true, resume previous media when given the signal.
+var stopServerSearch;
+var playBarHeight;
+var boxWidth;
+var textStartX;
var mainMenuTitleTemplateLandscape = {"font" : "oblique bolder 30pt arial", "lineWidth" : 9.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
"largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.4)"};
var mainTrackTemplate = {"font" : "bold 30pt Arial", "lineWidth" : 7.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
"largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
+var timeTemplate = {"font" : "bold 25pt Arial", "lineWidth" : 7.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
+ "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
+
var mediaTextTemplate2 = {"font" : "bold 20pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
"shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
var trackTextTemplate = {"font" : "bold 16pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
-var mediaTextTemplate2Landscape = {"font" : "bold 15pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
+var mediaTextTemplate2Landscape = {"font" : "bold 13pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
"shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
-var mediaTextTemplate3Landscape = {"font" : "bold 15pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
+var mediaTextTemplate3Landscape = {"font" : "bold 13pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
var trackTextTemplateLandscape = {"font" : "bold 11pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
console.log("Content discovery failed");
}
-function loadImages(callback)
+function setupSpeech()
{
- var loadedImages = 0;
- var numImages = 0;
-
- for (var src in audioContent)
- {
- numImages++;
- }
- for (var src in audioContent)
- {
- try
- {
- audioContent[src].coverArt = new Image();
- audioContent[src].coverArt.onload = function(){
-
- if (++loadedImages >= numImages) {
- imagesLoaded = true;
- callback(audioContent);
- }
- };
-
- audioContent[src].coverArt.onerror = function(e){
- audioContent[src].coverArt.src = "images/musicButton.png";
- };
-
- audioContent[src].coverArt.src = (audioContent[src].coverArtURI !== undefined && audioContent[src].coverArtURI !== "") ? audioContent[src].coverArtURI : "images/musicButton.png";
- }
- catch(err)
- {
- console.log("Failed to load audio cover image");
- }
- }
-}
+ console.log("MediaPlayer in setupSpeech");
-function updateMediaName(newArtist, newTitle, newCover)
-{
- var playBarHeight = mediaNameCanvas.height;
- var boxWidth = playBarHeight * 0.75;
- mediaNameCTX.clearRect(0,0,mediaNameCanvas.width, mediaNameCanvas.height);
+ speechObj = tizen.speech;
+ speechObj.vocalizeString(" ");
- if (currentPlayerType === "AUDIO")
+ try
{
- var shadeJump = 10;
- var alphaJump = 0.01;
- var currColor = 255;
- var currAlpha = 1.0;
-
- mediaNameCTX.fillStyle="rgba(30,30,30,0.5)";
- mediaNameCTX.strokeStyle="rgba(130,130,130,1)";
- mediaNameCTX.lineWidth = 5;
- mediaNameCTX.fillRect(0,0,mediaNameCanvas.width, playBarHeight);
- mediaNameCTX.strokeRect(-20,0,mediaNameCanvas.width + 40, playBarHeight);
-
- if (newCover === undefined || newCover.naturalWidth === undefined || newCover.naturalWidth <= 0)
- {
- newCover = musicIcon;
- }
+ var speechEventListener = {
+ onaudiostart: function(){console.log("MediaPlayer: onaudiostart received");},
+ onsoundstart: function(){console.log("MediaPlayer: onsoundstart received");},
+ onspeechstart: function(){console.log("MediaPlayer: onspeechstart received");},
+ onspeechend: function(){console.log("MediaPlayer: onspeechend received");},
+ onsoundend: function(){console.log("MediaPlayer: onsoundend received");},
+ onaudioend: function(){console.log("MediaPlayer: onaudioend received");},
+ onresult: function(result){
+
+ console.log("MediaPlayer: onresult received");
+
+ for (var i = 0; i < result.length; i++)
+ {
+ console.log("MediaPlayer: forloop, command = " + result[i]);
+ var commandFound = false;
- mediaNameCTX.drawImage(newCover, 20, (playBarHeight - boxWidth) / 2, boxWidth, boxWidth);
+ switch(result[i])
+ {
+ case "play":
+ playButtonClick();
+ commandFound = true;
+ break;
+ case "next":
+ nextButtonClick();
+ commandFound = true;
+ break;
+ case "previous":
+ backButtonClick();
+ commandFound = true;
+ break;
+ case "stop":
+ case "pause":
+ pauseButtonClick();
+ commandFound = true;
+ break;
+ default:
+ break;
+ }
- if (screenOrientation === "portrait")
- {
- var textStartX = boxWidth + 50;
- var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 70 , "zLoc" : 0, "width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 50, "wordWrap" : true});
- trackText.applyTemplate(mainMenuTitleTemplate);
- var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 70 + trackText.height, "zLoc" : 0, "width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 50, "wordWrap" : true});
- artistText.applyTemplate(mainTrackTemplate);
- artistText.yLoc = 70 + trackText.height;
- }
- else
- {
- var textStartX = boxWidth + 50;
- var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 50 , "zLoc" : 0, "width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
- trackText.applyTemplate(mainMenuTitleTemplateLandscape);
- var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 50, "zLoc" : 0, "width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
- artistText.applyTemplate(mainTrackTemplateLandscape);
- artistText.yLoc = 50 + trackText.height;
+ if (commandFound)
+ break;
+ }
+ },
+ onnomatch: function(result){console.log("MediaPlayer: onnomatch received ");},
+ onerror: function(error){console.log("MediaPlayer: onerror received");},
+ onstart: function(){console.log("MediaPlayer: onstart received");},
+ onend: function(){console.log("MediaPlayer: onend received");}
}
- trackText.drawObj();
- trackText.drawLargeShadow();
- artistText.drawObj();
+ speechObj.setCBListener(speechEventListener);
}
+ catch(err)
+ {
+ console.log("MediaPlayer setupSpeech FAILED + " + err.message);
+ }
+
}
-function fillMediaList(contentList)
+function onAudioContentLoaded(newContent)
{
- //Don't try and fill an empty content list or an audio list that hasn't finished loading the thumbnails
- if (contentList.length <=0 || (contentList === audioContent && !imagesLoaded))
- return false;
-
- var iconURI;
- var currentCanvas;
- var iconImg = new Image();
- var canvasW = mediaListItemW;
- var canvasH = mediaListItemH * 0.95 ;
-
- $("#mediaListItems").empty();
- var lightColor = false;
- for (var i=0; i < contentList.length; i++)
+ if (!newContent || newContent.length === 0)
{
- if (!lightColor)
- {
- $("#mediaListItems").append("<li><a href='#'>" +
- "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
- "</a></li>"
- );
- }
- else
- {
- $("#mediaListItems").append("<li><a href='#' class='lightColor'>" +
- "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
- "</a></li>"
- );
- }
-
- lightColor = !lightColor;
-
- currentCanvas = document.getElementById("canvasNum"+ i);
- currentCTX = currentCanvas.getContext("2d");
-
- // Set callback function for the new list item
- $("#canvasNum"+i).click(function () {
- listIndex = $(this).parent().parent().index();
-
- switch (currentPlayerType)
- {
- case "AUDIO":
- try
- {
- updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
- $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
- audioPlayer.load();
- }
- catch(err)
- {
- console.log("updateMediaName error: " + err.message);
- }
- break;
-
- case "VIDEO":
- try
- {
- updateMediaName(videoContent[listIndex].artists[0], audioContent[listIndex].title, vidIcon);
- $("#videoSrc").attr("src", videoContent[listIndex].contentURI);
- videoPlayer.load();
- $("#mediaList").fadeOut(300);
- }
- catch(err)
- {
- console.log("updateMediaName error: " + err.message);
- }
- break;
-
- case "IMAGE":
- try
- {
- $("#imagePlayer").css("background", "url(" + imageContent[listIndex].contentURI + ") no-repeat center");
- $("#imagePlayer").css("background-size", "contain");
- $("#mediaList").fadeOut(300);
- }
- catch(err)
- {
- console.log("updateMediaName error: " + err.message);
- }
- break;
-
- default:
- break;
- }
- });
-
- switch (currentPlayerType)
- {
- case "AUDIO":
- currentCTX.drawImage(audioContent[i].coverArt, 0, 0, canvasH, canvasH );
- var trackText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
- var artistText = new TextObject(currentCTX,{"text" : contentList[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
-
- break;
- case "VIDEO":
- currentCTX.drawImage(vidIcon, 0, 0, canvasH, canvasH );
- var artistText = new TextObject(currentCTX,{"text" : contentList[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
- var trackText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
-
- break;
- case "IMAGE":
- currentCTX.drawImage(imgIcon, 0, 0, canvasH, canvasH );
- var artistText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
- var trackText = new TextObject(currentCTX,{"text" : " ", "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
- break;
-
- default:
- break;
- }
-
- var mediaTextTemp1 = screenOrientation === "portrait" ? mediaTextTemplate2 : mediaTextTemplate2Landscape;
- var mediaTextTemp2 = screenOrientation === "portrait" ? mediaTextTemplate3 : mediaTextTemplate3Landscape;
- var trackTextTemp = screenOrientation === "portrait" ? trackTextTemplate : trackTextTemplateLandscape;
-
- trackText.applyTemplate(mediaTextTemp1);
- trackText.drawObj();
- trackText.applyTemplate(mediaTextTemp2);
- trackText.drawObj();
-
- artistText.applyTemplate(trackTextTemp);
- artistText.drawObj();
+ console.log("MediaPlayer: some content failed to load, trying again for " + audioPlayer.type);
+ audioPlayer.clearContent();
+ setTimeout(function(){getMedia(onAudioContentLoaded, "AUDIO");}, 3000);
+ return;
+ }
+ else
+ {
+ audioPlayer.updateContent(newContent, true);
+ audioPlayer.onContentLoaded();
}
-
- $("#mediaListItems li").css({"width" : mediaListItemW + "px", "height" : mediaListItemH + "px", "margin-bottom" : "10px"});
}
-function onContentItemArraySuccess(content)
+function onVideoContentLoaded(newContent)
{
- var emptyContent = true;
-
- if (!content || content === undefined || content.length <= 0)
- console.log("Invalid content for " + contentType);
+ if (!newContent || newContent.length === 0)
+ {
+ console.log("MediaPlayer: some content failed to load, trying again for " + videoPlayer.type);
+ videoPlayer.clearContent();
+ setTimeout(function(){getMedia(onVideoContentLoaded, "VIDEO");}, 3000);
+ return;
+ }
else
{
- emptyContent = false;
+ videoPlayer.updateContent(newContent, true);
+ videoPlayer.onContentLoaded();
}
+}
- switch (contentType)
+function onImageContentLoaded(newContent)
+{
+ if (!newContent || newContent.length === 0)
{
- case "AUDIO":
-
- if (!emptyContent)
- {
- try
- {
- audioContent = content;
- sortByAlpha(audioContent);
-
- $("#audioSrc").attr("src", audioContent[0].contentURI);
-
- var imgSources = [];
- for (var i = 0; i < audioContent.length; i++)
- {
- var iconURI = (audioContent[i].thumbnailURIs !== undefined && audioContent[i].thumbnailURIs !== null) ? audioContent[i].thumbnailURIs[0] : "images/musicButton.png";
- audioContent[i].coverArtURI = iconURI;
- }
-
- loadImages(fillMediaList);
- }
-
- catch (err)
- {
- console.log("Error when parsing audioContent");
- }
- }
-
- contentType = "VIDEO";
- break;
-
- case "VIDEO":
- if (!emptyContent)
- {
- videoContent = content;
- $("#videoSrc").attr("src", videoContent[0].contentURI);
- }
- contentType = "IMAGE";
- break;
-
- case "IMAGE":
- if (!emptyContent)
- {
- imageContent = content;
- $("#imagePlayer").css("background", "url(" + imageContent[0].contentURI + ") no-repeat center");
- $("#imagePlayer").css("background-size", "contain");
- }
- contentType = undefined;
- break;
-
- default:
- console.log("Undefined content search type");
- nextContentType = undefined;
- break;
+ console.log("MediaPlayer: some content failed to load, trying again for " + imagePlayer.type);
+ imagePlayer.clearContent();
+ setTimeout(function(){getMedia(onImageContentLoaded, "IMAGE");}, 3000);
+ return;
+ }
+ else
+ {
+ imagePlayer.updateContent(newContent, true);
+ imagePlayer.onContentLoaded();
}
-
- if (contentType !== undefined)
- getMedia(contentType);
}
-function getMedia(mediaType)
+function getMedia(callback, filterType)
{
+ console.log("MediaPlayer in getMedia");
var manager = tizen.content;
-
- var filter = new tizen.AttributeFilter("type", "EXACTLY", mediaType);
- manager.find(onContentItemArraySuccess, onError, null, filter);
+ if (manager)
+ {
+ var filter = new tizen.AttributeFilter("type", "EXACTLY", filterType);
+ manager.find(callback, onError, null, filter);
+ }
+ else
+ console.log("MediaPlayer failed to receive media, tizen.content is unavailable");
}
function showMediaMenu()
{
- $(".navButton").fadeIn(800);
+ console.log("MediaPlayer in showMediaMenu");
+ $(".navButton").show();
- switch(currentPlayerType)
+ switch(currentPlayer.type)
{
- case "AUDIO":
- //show audio player
- try
- {
- updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
- }
- catch(err)
- {
- console.log("updateMediaName failed for showMediaMenu (audio) : " + err.message);
- }
-
- $("#mediaName").fadeIn(800);
- $(".sortButton").fadeIn(800);
- currentPlayer.fadeIn(800);
-
- $("#mediaList").addClass("mediaListAudioList");
+ case "audio":
+ $("#mediaName").show();
+ $("#trackTime").show();
+ $(".sortButton").show();
+ currentPlayer.show();
+
+ if (screenOrientation === "landscape" )
+ $("#audioMediaList").addClass("landscape");
+ else
+ $("#audioMediaList").removeClass("landscape");
- if (screenOrientation === "landscape" )
- $("#mediaList").addClass("landscape");
- else
- $("#mediaList").removeClass("landscape");
+ $("#audioMediaList").show();
+ break;
- $("#mediaList").fadeIn(800);
- break;
+ case "video":
+ //show video
+ currentPlayer.show();
+ //setTimeout(function(){currentPlayer.show()}, 800); //The video element can't be faded, so wait a moment before showing
+ break;
- case "VIDEO":
- //show video
- setTimeout(function(){currentPlayer.show()}, 800); //The video element can't be faded, so wait a moment before showing
- break;
+ case "image":
+ //show image
+ currentPlayer.show();
+ break;
- case "IMAGE":
- //show image
- currentPlayer.fadeIn(800);
+ default:
+ console.log("Invalid player type");
break;
-
- default:
- console.log("Invalid player type");
- break;
}
}
function showMediaList()
{
- if ($("#mediaList").is(":visible"))
- $("#mediaList").fadeOut(300);
+ console.log("MediaPlayer in showMediaList");
+
+ if (currentMediaList.is(":visible"))
+ currentMediaList.hide();
else
{
- fillMediaList(currentContent);
- $("#mediaList").fadeIn(300);
+ currentMediaList.show();
}
}
function changeMenu(menuButtonId)
{
+ console.log("MediaPlayer in changeMenu");
var clickedButton = $("#" + menuButtonId);
var buttonWidth = clickedButton.width();
var buttonHeight = clickedButton.height();
var buttonBottom = clickedButton.css("bottom");
var buttonRight = clickedButton.css("right");
+/*
//Animate the clicked button slightly
clickedButton.animate({
bottom: screenOrientation === "portrait" ? "+=0" : "+=50",
clickedButton.css({"bottom": buttonBottom});
}
);
-
- $(".mainButton").fadeOut(300);
+*/
+ $(".mainButton").hide();
switch(menuButtonId)
{
- case ("mainMusicButton"):
- currentPlayer = $("#audioPlayer");
- currentPlayerControls = document.getElementById("audioPlayer");
- currentPlayerType = "AUDIO";
- currentContent = audioContent;
- showMediaMenu();
- break;
-
- case ("mainVideoButton"):
- currentPlayer = $("#videoPlayer");
- currentPlayerControls = document.getElementById("videoPlayer");
- currentPlayerType = "VIDEO";
- currentContent = videoContent;
- showMediaMenu();
- break;
-
- case ("mainImageButton"):
- currentPlayer = $("#imagePlayer");
- currentPlayerControls = imageControls;
- currentPlayerType = "IMAGE";
- currentContent = imageContent;
- showMediaMenu();
- break;
- default:
- console.log("Error: No menu by that name");
- break;
- }
-}
-
-function showMainMenu()
-{
- currentPlayerControls.pause();
+ case ("mainMusicButton"):
+ speechObj.vocalizeString("Music player");
+ currentMenu = "audio";
+ currentPlayer = audioPlayer;
+ currentMediaList = $("#audioMediaList");
+ localStorage.prevMenu = "mainMusicButton";
+
+ if (audioPlayer.currentAudioContent && audioPlayer.currentAudioContent.contentURI)
+ {
+ localStorage.prevAudioTrack = audioPlayer.currentAudioContent.contentURI
+ localStorage.prevAudioTime = audioPlayer.playerControls.currentTime;
+ }
- $("#playButton").attr("src","images/playButton.png");
+ localStorage.prevVideo = undefined;
+ localStorage.prevVideoTime = undefined;
- //If the media list is showing, hide it. Remove the mediaListAudioList class if it exists so that it will resize properly
- if ($("#mediaList").is(":visible"))
- $("#mediaList").fadeOut(300, function(){$("#mediaList").removeClass("mediaListAudioList");});
+ if (!audioMediaListLoaded)
+ audioPlayer.fillMediaList();
- $(".navButton").fadeOut(300);
- $(".sortButton").fadeOut(300);
- $("#mediaName").fadeOut(300);
+ showMediaMenu();
+ break;
- if (currentPlayerType !== "VIDEO")
- currentPlayer.fadeOut(300);
- else
- currentPlayer.hide();
+ case ("mainVideoButton"):
+ speechObj.vocalizeString("Video player");
+ currentMenu = "video";
+ currentPlayer = videoPlayer;
+ currentMediaList = $("#videoMediaList");
+ localStorage.prevMenu = "mainVideoButton";
+ if (videoPlayer.currentVideoContent && videoPlayer.currentVideoContent.contentURI)
+ {
+ localStorage.prevVideo = videoPlayer.currentVideoContent.contentURI
+ localStorage.prevVideoTime = videoPlayer.playerControls.currentTime;
+ }
- $(".mainButton").css({"opacity": "100"});
- $(".mainButton").fadeIn(800);
-}
+ localStorage.prevAudioTime = undefined;
+ localStorage.prevAudioTrack = undefined;
-function sortByAlpha(contentToSort)
-{
- //If contentToSort is undefined it's because the request came from the sortBy buttons
- if (contentToSort === undefined)
- contentToSort = audioContent;
+ if (!videoMediaListLoaded)
+ videoPlayer.fillMediaList();
- contentToSort.sort(function (a,b) {
- var first = a.title.toLowerCase();
- var second = b.title.toLowerCase();
+ showMediaMenu();
+ break;
- if (first < second)
- return -1;
- if (first > second)
- return 1;
+ case ("mainImageButton"):
+ speechObj.vocalizeString("Picture viewer");
+ currentMenu = "image";
+ currentPlayer = imagePlayer;
+ currentMediaList = $("#imageMediaList");
+ localStorage.prevMenu = "mainImageButton";
- return 0;
- });
+ if (!imageMediaListLoaded)
+ imagePlayer.fillMediaList();
- fillMediaList(contentToSort);
+ showMediaMenu();
+ break;
+ default:
+ console.log("Error: No menu by that name");
+ break;
+ }
}
-function sortByArtist(contentToSort)
+function showMainMenu()
{
- if (contentToSort === undefined)
- contentToSort = audioContent;
+ console.log("MediaPlayer in showMainMenu, clearing all localStorage...");
+ currentMenu = "main";
+ localStorage.prevMenu = "MAIN";
+ localStorage.prevAudioTime = undefined;
+ localStorage.prevAudioTrack = undefined;
+ localStorage.prevVideo = undefined;
+ localStorage.prevVideoTime = undefined;
+ localStorage.prevImage = undefined;
- contentToSort.sort(function (a,b) {
- var first = a.artists[0].toLowerCase();
- var second = b.artists[0].toLowerCase();
+ currentPlayer.pause();
- if (first < second)
- return -1;
- if (first > second)
- return 1;
+ //If the media list is showing, hide it. Remove the mediaListAudioList class if it exists so that it will resize properly
+ if (currentMediaList.is(":visible"))
+ currentMediaList.hide();
+
+ $(".navButton").hide();
+ $(".sortButton").hide();
+ $("#mediaName").hide();
+ $("#trackTime").hide();
+ $(".player").hide();
+ $(".mainButton").css({"opacity": "100"});
+ $(".mainButton").show();
+}
- return 0;
- });
+function sortByAlpha(contentToSort)
+{
+ currentPlayer.sortByAlpha();
+}
- fillMediaList(contentToSort);
+function sortByArtist(contentToSort)
+{
+ currentPlayer.sortByArtist();
}
function sortByAlbum(contentToSort)
{
- if (contentToSort === undefined)
- contentToSort = audioContent;
-
- contentToSort.sort(function (a,b) {
- var first = a.album.toLowerCase();
- var second = b.album.toLowerCase();
+ currentPlayer.sortByAlbum();
+}
- if (first < second)
- return -1;
- if (first > second)
- return 1;
+/**************************************** NAVIGATION FUNCTIONS *******************************************/
- return 0;
- });
+// This function is called once a file being loaded is ready to play
+function playLoadedMedia()
+{
+ audioPlayer.playLoadedMedia();
+}
- fillMediaList(contentToSort);
+function videoLoaded()
+{
+ videoPlayer.videoLoaded();
}
-/**************************************** NAVIGATION FUNCTIONS *******************************************/
function playButtonClick()
{
- if (currentPlayerControls.paused)
- {
- currentPlayerControls.play();
- $("#playButton").attr("src","images/pauseButton.png");
- }
+ console.log("MediaPlayer in playButtonClick");
+ if (!currentPlayer.playing())
+ currentPlayer.play();
else
+ currentPlayer.pause();
+}
+
+function pauseButtonClick()
+{
+ console.log("MediaPlayer in pauseButtonClick");
+ if (currentPlayer.playing())
{
- currentPlayerControls.pause();
- $("#playButton").attr("src","images/playButton.png");
+ currentPlayer.pause();
}
}
function backButtonClick()
{
- switch (currentPlayerType)
- {
- case "AUDIO":
- if (audioContent)
- {
- if (listIndex > 0 )
- listIndex--;
- else
- listIndex = imageContent.length - 1;
-
- audioPlayer.pause();
- $("#playButton").attr("src","images/playButton.png");
-
- $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
- updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
- audioPlayer.load();
- }
- break;
-
- case "VIDEO":
- if (videoContent)
- {
- if (videoIndex > 0 )
- videoIndex--;
- else
- videoIndex = imageContent.length - 1;
-
- if ($("#mediaList").is(":visible"))
- videoPlayer.pause();
-
- $("#playButton").attr("src","images/playButton.png");
- $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
- videoPlayer.load();
- }
- break;
-
- case "IMAGE":
- if (imageContent)
- {
- if (imageIndex > 0 )
- imageIndex--;
- else
- imageIndex = imageContent.length - 1;
-
- $("#imagePlayer").css("background", "url(" + imageContent[imageIndex].contentURI + ") no-repeat center");
- $("#imagePlayer").css("background-size", "contain");
- }
- break;
-
- default:
- console.log("Content failure");
- break;
- }
+ console.log("MediaPlayer in backButtonClick");
+ currentPlayer.previous();
}
function nextButtonClick()
{
- switch (currentPlayerType)
- {
- case "AUDIO":
- if (audioContent)
- {
- if (audioContent.length > (listIndex + 1))
- listIndex++;
- else
- listIndex = 0;
-
- audioPlayer.pause();
- $("#playButton").attr("src","images/playButton.png");
- $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
- updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
- audioPlayer.load();
- }
- break;
-
- case "VIDEO":
- if (videoContent)
- {
- if (videoContent.length > (videoIndex + 1))
- videoIndex++;
- else
- videoIndex = 0;
-
- videoPlayer.pause();
- $("#playButton").attr("src","images/playButton.png");
- $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
- videoPlayer.load();
- }
- break;
-
- case "IMAGE":
- if (imageContent)
- {
- if (imageContent.length > (imageIndex + 1))
- imageIndex++;
- else
- imageIndex = 0;
-
- $("#imagePlayer").css("background", "url(" + imageContent[imageIndex].contentURI + ") no-repeat center");
- $("#imagePlayer").css("background-size", "contain");
- }
- break;
-
- default:
- console.log("Content failure");
- break;
- }
+ console.log("MediaPlayer in nextButtonClick");
+ currentPlayer.next();
}
/**************************************** END NAVIGATION FUNCTIONS *******************************************/
function resizeMainMenu()
{
- $("#mediaList").fadeOut(0);
+ console.log("MediaPlayer in resizeMainMenu");
+
+ currentMediaList.hide();
screenWidth = window.innerWidth;
screenHeight = window.innerHeight;
screenOrientation = screenWidth < screenHeight ? "portrait" : "landscape";
function resizePlayerPage()
{
- audioPlayer = document.getElementById("audioPlayer");
- videoPlayer = document.getElementById("videoPlayer");
+ console.log("MediaPlayer in resizePlayerPage");
+
screenWidth = window.innerWidth;
screenHeight = window.innerHeight;
$("#nextButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": ((screenWidth / 2) + (buttonWidth *2)) + "px"});
$("#returnButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": padding + "px"});
$("#listButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": (screenWidth - buttonWidth - padding * 2) + "px"});
- $("#playButton").css({"width": buttonWidth * 1.3 + "px", "height": buttonWidth * 1.3 + "px", "top": padding * 0.3 + "px", "left": (screenWidth / 2) - (buttonWidth / 2) + "px"});
+ $("#playButton").css({"width": buttonWidth * 1.15 + "px", "height": buttonWidth * 1.15 + "px", "top": padding * 0.3 + "px", "left": (screenWidth / 2) - (buttonWidth / 2) + "px"});
- mediaNameCanvas.width = (screenWidth);
- mediaNameCanvas.height = (screenHeight * 0.34) - (buttonWidth + (2 * padding));
- mediaNameCanvas.style.top = (buttonWidth + (2 * padding) ) + "px";
- mediaNameCanvas.style.left = "0px";
+ trackTimeCanvas.width = mediaNameCanvas.width = (screenWidth);
+ trackTimeCanvas.height = mediaNameCanvas.height = (screenHeight * 0.34) - (buttonWidth + (2 * padding));
+ trackTimeCanvas.style.top = mediaNameCanvas.style.top = (buttonWidth + (2 * padding) ) + "px";
+ trackTimeCanvas.style.left = mediaNameCanvas.style.left = "0px";
var sortButtonTop = (buttonWidth + (2 * padding) ) + mediaNameCanvas.height - (buttonWidth * 1.3);
var sortButtonWidth = buttonWidth * 2.5;
var buttonSpacing = screenWidth / 5;
- mediaListItemW = $("#mediaList").width() * 0.92;
- mediaListItemH = $("#mediaList").height() / 10;
+ mediaListItemW = $("#videoMediaList").width() * 0.92;
+ mediaListItemH = $("#videoMediaList").height() / 10;
}
function resizeAll()
{
+ console.log("MediaPlayer in resizeAll");
resizeMainMenu();
resizePlayerPage();
}
function swipe(direction, object)
{
-
+ console.log("MediaPlayer in swipe");
switch (object)
{
case "mediaName":
}
}
+function toggleNightMode(nightModeValue)
+{
+ if (nightMode !== nightModeValue)
+ {
+ Array.prototype.forEach.call (document.querySelectorAll ('*'), function (el) {el.classList.toggle('night');});
+ nightMode = nightModeValue;
+ }
+}
+
function init()
{
- musicIcon.src = "images/musicButton.png";
- vidIcon.src = "images/videoButton.png";
- imgIcon.src = "images/imageButton.png";
- imageControls = new ImageControls();
+ console.log("MediaPlayer in init");
+ musicIcon.src = "images/musicIcon.png";
+ vidIcon.src = "images/videoIcon.png";
+ imgIcon.src = "images/imageIcon.png";
mediaNameCanvas = document.getElementById("mediaName");
mediaNameCTX = mediaNameCanvas.getContext("2d");
+ trackTimeCanvas = document.getElementById("trackTime");
+ trackTimeCTX = trackTimeCanvas.getContext("2d");
+ playBarHeight = mediaNameCanvas.height;
+ boxWidth = playBarHeight * 0.75;
+ textStartX = boxWidth + 50;
+
+ var vehicle = tizen.vehicle;
+
+
+ /* Subscribe to AMB NightMode signal, and switch colors
+ * upon receipt of the signal
+ */
+
+ if (vehicle && vehicle !== undefined)
+ {
+ var getVal = vehicle.get("NightMode");
+
+ //Check that NightMode returned a value before trying to hook up to it
+ if (getVal)
+ {
+ toggleNightMode(getVal.nightMode);
+ }
+
+ /* Subscribe to AMB NightMode signal, and switch colors
+ * upon receipt of the signal
+ */
+
+ vehicle.subscribe("NightMode",function(value) {
+ console.log("MediaPlayer: Day / Night mode changed to " + value.nightMode);
+ toggleNightMode(value.nightMode);
+ });
+
+
+ /* Subscribe to AMB DrivingMode signal, and pause video
+ * upon receipt of the signal
+ */
+
+
+ vehicle.subscribe("DrivingMode",function(value) {
+ console.log("MediaPlayer: DrivingMode changed to " + value.drivingMode);
+
+ if (value.drivingMode > 0 && currentPlayer.type === "video" && currentPlayer.playing())
+ {
+ console.log("MediaPlayer: pausing video due to vehicle motion");
+ currentPlayer.pause();
+ waitingToResumeVideo = true;
+ }
+ else if (value.drivingMode === 0 && currentPlayer.type === "video" && waitingToResumeVideo)
+ {
+ console.log("MediaPlayer: vehicle has stopped, resuming video");
+ currentPlayer.play();
+ waitingToResumeVideo = false;
+ }
+ });
+ }
+
+ //Setup voice control
+ if (tizen.speech)
+ setupSpeech();
+ else {
+ console.log("MediaPlayer: Speech Recognition not running, voice control will be unavailable");
+ speechObj = {
+ vocalizeString: function(item) { console.log(item); }
+ };
+ }
+
+ audioPlayer = new MediaPlayer("audio");
+ videoPlayer = new MediaPlayer("video");
+ imagePlayer = new MediaPlayer("image");
+ currentPlayer = audioPlayer;
//Resize all items and search for local media
resizeAll();
- getMedia(contentType);
+
+ if (localStorage.prevMenu && localStorage.prevMenu !== "MAIN")
+ changeMenu(localStorage.prevMenu)
+ else
+ showMainMenu();
+
+ getMedia(onAudioContentLoaded, "AUDIO");
+ getMedia(onVideoContentLoaded, "VIDEO");
+ getMedia(onImageContentLoaded, "IMAGE");
+
+ //Check if DLNA plugin is installed. If so, scan for media.
+ if (tizen.mediaserver)
+ {
+ //Currently no success signal, so continue trying until a server is found. Once that
+ //happens, clear the stopServerSearch interval
+
+ stopServerSearch = setInterval(function(){console.log("MediaPlayer searching for remote media..."); tizen.mediaserver.scanNetwork(foundMediaServer);}, 5000);
+ }
+ else
+ console.log("MediaPlayer: No DLNA server running, using local media only...");
//Prevent highlighting
window.ondragstart = function() { return false; }
}
}
});
+
+ document.getElementById('videoPlayer').addEventListener("playing", function() {
+ $("#playButton").toggleClass('playing', true);
+ $("#navigationButtons").hide();
+ }, false);
+ document.getElementById('videoPlayer').addEventListener("pause", function() {
+ $("#playButton").toggleClass('playing', false);
+ $("#navigationButtons").show();
+ }, false);
+ document.getElementById('videoPlayer').addEventListener("ended", function() {
+ $("#playButton").toggleClass('playing', false);
+ $("#navigationButtons").show();
+ }, false);
+ document.getElementById('audioPlayer').addEventListener("playing", function() {
+ $("#playButton").toggleClass('playing', true);
+ }, false);
+ document.getElementById('audioPlayer').addEventListener("pause", function() {
+ $("#playButton").toggleClass('playing', false);
+ }, false);
+ document.getElementById('audioPlayer').addEventListener("ended", function() {
+ $("#playButton").toggleClass('playing', false);
+ }, false);
+ document.getElementById('imagePlayer').addEventListener("click", function() {
+ if (!imagePlayer.playing)
+ {
+ // next picture
+ nextButtonClick();
+ }
+ else
+ {
+ // pause the slideshow and fade in the controls
+ imagePlayer.pause();
+ $("#navigationButtons").show();
+ }
+ }, false);
}
$(document).ready(function () {