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 var currentMenu = "main";
12 var resizeCB = resizeMainMenu;
15 var screenOrientation;
18 var contentType = "AUDIO";
24 var currentPlayerType = "AUDIO";
25 var currentPlayerControls;
31 var vidIcon = new Image();
32 var imgIcon = new Image();
33 var musicIcon = new Image();
34 var imagesLoaded = false;
38 var loadAndPlay = false;
40 var currentFileLoaded = false;
44 var nightMode = false;
47 var mainMenuTitleTemplateLandscape = {"font" : "oblique bolder 30pt arial", "lineWidth" : 9.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
48 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.4)"};
50 var mainMenuTitleTemplate = {"font" : "oblique bolder 40pt arial", "lineWidth" : 9.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
51 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.4)"};
53 var mainTrackTemplateLandscape = {"font" : "bold 20pt Arial", "lineWidth" : 7.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
54 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
56 var mainTrackTemplate = {"font" : "bold 30pt Arial", "lineWidth" : 7.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
57 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
59 var mediaTextTemplate2 = {"font" : "bold 20pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
60 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
62 var mediaTextTemplate3 = {"font" : "bold 20pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
64 var trackTextTemplate = {"font" : "bold 16pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
66 var mediaTextTemplate2Landscape = {"font" : "bold 15pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
67 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
69 var mediaTextTemplate3Landscape = {"font" : "bold 15pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
71 var trackTextTemplateLandscape = {"font" : "bold 11pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
74 var mediaTextTemplate = {"font" : "bold 20pt Arial", "fillStyle" : "", "textAlign" : "left",
75 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 12, "shadowColor" : "red"};
79 console.log("Content discovery failed");
82 function setupSpeech()
84 console.log("MediaPlayer in setupSpeech");
86 speechObj = tizen.speech;
90 var speechEventListener = {
91 onaudiostart: function(){console.log("MediaPlayer: onaudiostart received");},
92 onsoundstart: function(){console.log("MediaPlayer: onsoundstart received");},
93 onspeechstart: function(){console.log("MediaPlayer: onspeechstart received");},
94 onspeechend: function(){console.log("MediaPlayer: onspeechend received");},
95 onsoundend: function(){console.log("MediaPlayer: onsoundend received");},
96 onaudioend: function(){console.log("MediaPlayer: onaudioend received");},
97 onresult: function(result){
99 console.log("MediaPlayer: onresult received");
101 for (var i = 0; i < result.length; i++)
103 console.log("MediaPlayer: forloop, command = " + result[i]);
104 var commandFound = false;
133 onnomatch: function(result){console.log("MediaPlayer: onnomatch received ");},
134 onerror: function(error){console.log("MediaPlayer: onerror received");},
135 onstart: function(){console.log("MediaPlayer: onstart received");},
136 onend: function(){console.log("MediaPlayer: onend received");}
139 speechObj.setCBListener(speechEventListener);
144 console.log("MediaPlayer setupSpeech FAILED + " + err.message);
149 function loadImages(callback)
151 console.log("MediaPlayer in loadImages");
153 var loadedImages = 0;
156 for (var src in audioContent)
160 for (var src in audioContent)
164 audioContent[src].coverArt = new Image();
165 audioContent[src].coverArt.onload = function(){
167 if (++loadedImages >= numImages) {
169 callback(audioContent);
173 audioContent[src].coverArt.onerror = function(e){
174 audioContent[src].coverArt.src = "images/musicIcon.png";
177 audioContent[src].coverArt.src = (audioContent[src].coverArtURI !== undefined && audioContent[src].coverArtURI !== "") ? audioContent[src].coverArtURI : "images/musicIcon.png";
181 console.log("Failed to load audio cover image");
186 function updateMediaName(newArtist, newTitle, newCover)
188 console.log("MediaPlayer in updateMediaName");
190 var playBarHeight = mediaNameCanvas.height;
191 var boxWidth = playBarHeight * 0.75;
192 mediaNameCTX.clearRect(0,0,mediaNameCanvas.width, mediaNameCanvas.height);
194 if (currentPlayerType === "AUDIO")
197 var alphaJump = 0.01;
201 mediaNameCTX.fillStyle="rgba(30,30,30,0.5)";
202 mediaNameCTX.strokeStyle="rgba(130,130,130,1)";
203 mediaNameCTX.lineWidth = 5;
204 mediaNameCTX.fillRect(0,0,mediaNameCanvas.width, playBarHeight);
205 mediaNameCTX.strokeRect(-20,0,mediaNameCanvas.width + 40, playBarHeight);
207 if (newCover === undefined || newCover.naturalWidth === undefined || newCover.naturalWidth <= 0)
209 newCover = musicIcon;
212 mediaNameCTX.drawImage(newCover, 20, (playBarHeight - boxWidth) / 2, boxWidth, boxWidth);
214 if (screenOrientation === "portrait")
216 var textStartX = boxWidth + 50;
217 var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 70 , "zLoc" : 0,
218 "width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 50, "wordWrap" : true});
219 trackText.applyTemplate(mainMenuTitleTemplate);
220 var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 70 + trackText.height, "zLoc" : 0,
221 "width" : mediaNameCanvas.width - textStartX, "height" : 50, "lineHeight" : 50, "wordWrap" : true});
222 artistText.applyTemplate(mainTrackTemplate);
223 artistText.yLoc = 70 + trackText.height;
227 var textStartX = boxWidth + 50;
228 var trackText = new TextObject(mediaNameCTX,{"text" : newTitle, "xLoc" : textStartX, "yLoc" : 50 , "zLoc" : 0,
229 "width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
230 trackText.applyTemplate(mainMenuTitleTemplateLandscape);
231 var artistText = new TextObject(mediaNameCTX,{"text" : newArtist, "xLoc" : textStartX, "yLoc" : 50, "zLoc" : 0,
232 "width" : mediaNameCanvas.width - textStartX, "height" : 30, "lineHeight" : 30, "wordWrap" : true});
233 artistText.applyTemplate(mainTrackTemplateLandscape);
234 artistText.yLoc = 50 + trackText.height;
238 trackText.drawLargeShadow();
239 artistText.drawObj();
244 function fillMediaList(contentList)
246 console.log("MediaPlayer in fillMediaList");
247 //Don't try and fill an empty content list or an audio list that hasn't finished loading the thumbnails
248 if (contentList === undefined || contentList === null || contentList.length <=0 || (contentList === audioContent && !imagesLoaded))
253 var iconImg = new Image();
254 var canvasW = mediaListItemW;
255 var canvasH = mediaListItemH * 0.95 ;
257 $("#mediaListItems").empty();
258 var lightColor = false;
259 for (var i=0; i < contentList.length; i++)
265 $("#mediaListItems").append("<li><a href='#' class='night'>" +
266 "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
272 $("#mediaListItems").append("<li><a href='#'>" +
273 "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
282 $("#mediaListItems").append("<li><a href='#' class='lightColor night'>" +
283 "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
289 $("#mediaListItems").append("<li><a href='#' class='lightColor'>" +
290 "<canvas id=canvasNum" + i + " width=" + canvasW + " height=" + canvasH + "> </canvas>" +
297 lightColor = !lightColor;
299 currentCanvas = document.getElementById("canvasNum"+ i);
300 currentCTX = currentCanvas.getContext("2d");
302 // Set callback function for the new list item
303 $("#canvasNum"+i).click(function () {
304 listIndex = $(this).parent().parent().index();
306 switch (currentPlayerType)
311 $("#playButton").toggleClass('playing', false);
313 updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
314 $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
320 console.log("updateMediaName error: " + err.message);
327 $("#playButton").toggleClass('playing', false);
328 updateMediaName(videoContent[listIndex].artists[0], audioContent[listIndex].title, vidIcon);
329 $("#videoSrc").attr("src", videoContent[listIndex].contentURI);
331 $("#mediaList").fadeOut(300);
335 console.log("updateMediaName error: " + err.message);
342 $("#playButton").toggleClass('playing', false);
343 $("#imagePlayer").css("background", "url(" + imageContent[listIndex].contentURI + ") no-repeat center");
344 $("#imagePlayer").css("background-size", "contain");
345 $("#mediaList").fadeOut(300);
349 console.log("updateMediaName error: " + err.message);
358 switch (currentPlayerType)
361 currentCTX.drawImage(audioContent[i].coverArt, 0, 0, canvasH, canvasH );
362 var trackText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
363 var artistText = new TextObject(currentCTX,{"text" : contentList[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
367 currentCTX.drawImage(vidIcon, 0, 0, canvasH, canvasH );
368 var artistText = new TextObject(currentCTX,{"text" : contentList[i].artists[0], "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
369 var trackText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
373 currentCTX.drawImage(imgIcon, 0, 0, canvasH, canvasH );
374 var artistText = new TextObject(currentCTX,{"text" : contentList[i].title, "xLoc" : canvasH + 20, "yLoc" : canvasH / 2.5 , "zLoc" : 0});
375 var trackText = new TextObject(currentCTX,{"text" : " ", "xLoc" : canvasH + 20, "yLoc" : canvasH / 1.1 , "zLoc" : 0});
382 var mediaTextTemp1 = screenOrientation === "portrait" ? mediaTextTemplate2 : mediaTextTemplate2Landscape;
383 var mediaTextTemp2 = screenOrientation === "portrait" ? mediaTextTemplate3 : mediaTextTemplate3Landscape;
384 var trackTextTemp = screenOrientation === "portrait" ? trackTextTemplate : trackTextTemplateLandscape;
386 trackText.applyTemplate(mediaTextTemp1);
388 trackText.applyTemplate(mediaTextTemp2);
391 artistText.applyTemplate(trackTextTemp);
392 artistText.drawObj();
395 $("#mediaListItems li").css({"width" : mediaListItemW + "px", "height" : mediaListItemH + "px", "margin-bottom" : "10px"});
398 function onContentItemArraySuccess(content)
400 console.log("MediaPlayer in onContentItemArraySuccess");
401 var emptyContent = true;
403 if (!content || content === undefined || content.length <= 0)
404 console.log("Invalid content for " + contentType);
407 emptyContent = false;
418 audioContent = content;
419 sortByAlpha(audioContent);
421 $("#audioSrc").attr("src", audioContent[0].contentURI);
426 for (var i = 0; i < audioContent.length; i++)
428 var iconURI = (audioContent[i].thumbnailURIs !== undefined && audioContent[i].thumbnailURIs !== null) ? audioContent[i].thumbnailURIs[0] : "images/musicIcon.png";
429 audioContent[i].coverArtURI = iconURI;
432 loadImages(fillMediaList);
437 console.log("Error when parsing audioContent");
441 contentType = "VIDEO";
447 videoContent = content;
448 $("#videoSrc").attr("src", videoContent[0].contentURI);
450 contentType = "IMAGE";
456 imageContent = content;
457 $("#imagePlayer").css("background", "url(" + imageContent[0].contentURI + ") no-repeat center");
458 $("#imagePlayer").css("background-size", "contain");
460 contentType = undefined;
464 console.log("Undefined content search type");
465 nextContentType = undefined;
469 if (contentType !== undefined)
470 getMedia(contentType);
473 function getMedia(mediaType)
475 console.log("MediaPlayer in getMedia");
476 var manager = tizen.content;
478 var filter = new tizen.AttributeFilter("type", "EXACTLY", mediaType);
479 manager.find(onContentItemArraySuccess, onError, null, filter);
482 function showMediaMenu()
484 console.log("MediaPlayer in showMediaMenu");
485 $(".navButton").fadeIn(800);
487 switch(currentPlayerType)
493 updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
497 console.log("updateMediaName failed for showMediaMenu (audio) : " + err.message);
500 $("#mediaName").fadeIn(800);
501 $(".sortButton").fadeIn(800);
502 currentPlayer.fadeIn(800);
504 $("#mediaList").addClass("mediaListAudioList");
506 if (screenOrientation === "landscape" )
507 $("#mediaList").addClass("landscape");
509 $("#mediaList").removeClass("landscape");
511 $("#mediaList").fadeIn(800);
516 setTimeout(function(){currentPlayer.show()}, 800); //The video element can't be faded, so wait a moment before showing
521 currentPlayer.fadeIn(800);
525 console.log("Invalid player type");
530 function showMediaList()
532 console.log("MediaPlayer in showMediaList");
533 if ($("#mediaList").is(":visible"))
534 $("#mediaList").fadeOut(300);
537 fillMediaList(currentContent);
538 $("#mediaList").fadeIn(300);
542 function changeMenu(menuButtonId)
544 console.log("MediaPlayer in changeMenu");
545 var clickedButton = $("#" + menuButtonId);
546 var buttonWidth = clickedButton.width();
547 var buttonHeight = clickedButton.height();
548 var buttonBottom = clickedButton.css("bottom");
549 var buttonRight = clickedButton.css("right");
551 //Animate the clicked button slightly
552 clickedButton.animate({
553 bottom: screenOrientation === "portrait" ? "+=0" : "+=50",
554 right: screenOrientation === "portrait" ? "+=50" : "+=0",
558 //Reset the size once done
560 clickedButton.width(buttonWidth);
561 clickedButton.height(buttonHeight);
563 if (screenOrientation === "portrait")
564 clickedButton.css({"right": buttonRight});
566 clickedButton.css({"bottom": buttonBottom});
570 $(".mainButton").fadeOut(300);
574 case ("mainMusicButton"):
575 currentMenu = "audio";
576 currentPlayer = $("#audioPlayer");
577 currentPlayerControls = document.getElementById("audioPlayer");
578 currentPlayerType = "AUDIO";
579 currentContent = audioContent;
583 case ("mainVideoButton"):
584 currentMenu = "video";
585 currentPlayer = $("#videoPlayer");
586 currentPlayerControls = document.getElementById("videoPlayer");
587 currentPlayerType = "VIDEO";
588 currentContent = videoContent;
592 case ("mainImageButton"):
593 currentMenu = "image";
594 currentPlayer = $("#imagePlayer");
595 currentPlayerControls = imageControls;
596 currentPlayerType = "IMAGE";
597 currentContent = imageContent;
601 console.log("Error: No menu by that name");
606 function showMainMenu()
608 console.log("MediaPlayer in showMainMenu");
609 currentMenu = "main";
610 currentPlayerControls.pause();
612 $("#playButton").toggleClass('playing', false);
614 //If the media list is showing, hide it. Remove the mediaListAudioList class if it exists so that it will resize properly
615 if ($("#mediaList").is(":visible"))
616 $("#mediaList").fadeOut(300, function(){$("#mediaList").removeClass("mediaListAudioList");});
618 $(".navButton").fadeOut(300);
619 $(".sortButton").fadeOut(300);
620 $("#mediaName").fadeOut(300);
622 if (currentPlayerType !== "VIDEO")
623 currentPlayer.fadeOut(300);
625 currentPlayer.hide();
628 $(".mainButton").css({"opacity": "100"});
629 $(".mainButton").fadeIn(800);
632 function sortByAlpha(contentToSort)
634 console.log("MediaPlayer in sortByAlpha");
635 //If contentToSort is undefined it's because the request came from the sortBy buttons
636 if (contentToSort === undefined)
637 contentToSort = audioContent;
639 contentToSort.sort(function (a,b) {
640 var first = a.title.toLowerCase();
641 var second = b.title.toLowerCase();
651 fillMediaList(contentToSort);
654 function sortByArtist(contentToSort)
656 console.log("MediaPlayer in sortByArtist");
657 if (contentToSort === undefined)
658 contentToSort = audioContent;
660 contentToSort.sort(function (a,b) {
661 var first = a.artists[0].toLowerCase();
662 var second = b.artists[0].toLowerCase();
672 fillMediaList(contentToSort);
675 function sortByAlbum(contentToSort)
677 console.log("MediaPlayer in sortByAlbum");
678 if (contentToSort === undefined)
679 contentToSort = audioContent;
681 contentToSort.sort(function (a,b) {
682 var first = a.album.toLowerCase();
683 var second = b.album.toLowerCase();
693 fillMediaList(contentToSort);
696 /**************************************** NAVIGATION FUNCTIONS *******************************************/
699 // A timer that will produce an error if a file can't be loaded.
700 function startLoadTimer()
702 console.log("MediaPlayer in startLoadTimer");
703 if (loadTimer !== undefined)
704 clearTimeout(loadTimer);
706 loadTimer = setTimeout(
708 if (currentMenu != "main")
710 $("#playButton").toggleClass('playing', false);
711 alert("File failed to load! - " + audioContent[listIndex].artists[0] + " : " + audioContent[listIndex].title);
712 currentFileLoaded = false;
716 // This function is called once a file being loaded is ready to play
717 function playLoadedMedia()
719 console.log("MediaPlayer in playLoadedMedia");
720 currentFileLoaded = true;
722 if (loadTimer !== undefined)
723 clearTimeout(loadTimer);
727 currentPlayerControls.play();
729 $("#playButton").toggleClass('playing', true);
734 function playButtonClick()
736 console.log("MediaPlayer in playButtonClick");
737 if (currentFileLoaded)
739 if (currentPlayerControls.paused)
741 $("#playButton").toggleClass('playing', true);
742 currentPlayerControls.play();
746 $("#playButton").toggleClass('playing', false);
747 currentPlayerControls.pause();
751 alert(audioContent[listIndex].artists[0] + " : " + audioContent[listIndex].title + " failed to load, please select another file");
754 function pauseButtonClick()
756 console.log("MediaPlayer in pauseButtonClick");
757 if (!currentPlayerControls.paused)
759 currentPlayerControls.pause();
760 $("#playButton").toggleClass('playing', false);
764 function backButtonClick()
766 console.log("MediaPlayer in backButtonClick");
767 switch (currentPlayerType)
775 listIndex = imageContent.length - 1;
780 $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
781 updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
793 videoIndex = imageContent.length - 1;
795 if ($("#mediaList").is(":visible"))
798 $("#playButton").toggleClass('playing', true);
799 $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
810 imageIndex = imageContent.length - 1;
812 $("#imagePlayer").css("background", "url(" + imageContent[imageIndex].contentURI + ") no-repeat center");
813 $("#imagePlayer").css("background-size", "contain");
818 console.log("Content failure");
824 function nextButtonClick()
826 console.log("MediaPlayer in nextButtonClick");
827 switch (currentPlayerType)
832 if (audioContent.length > (listIndex + 1))
840 $("#audioSrc").attr("src", audioContent[listIndex].contentURI);
841 updateMediaName(audioContent[listIndex].artists[0], audioContent[listIndex].title, audioContent[listIndex].coverArt);
850 if (videoContent.length > (videoIndex + 1))
856 $("#playButton").toggleClass('playing', true);
857 $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
865 if (imageContent.length > (imageIndex + 1))
870 $("#imagePlayer").css("background", "url(" + imageContent[imageIndex].contentURI + ") no-repeat center");
871 $("#imagePlayer").css("background-size", "contain");
876 console.log("Content failure");
881 /**************************************** END NAVIGATION FUNCTIONS *******************************************/
883 function resizeMainMenu()
885 console.log("MediaPlayer in resizeMainMenu");
887 $("#mediaList").fadeOut(0);
888 screenWidth = window.innerWidth;
889 screenHeight = window.innerHeight;
890 screenOrientation = screenWidth < screenHeight ? "portrait" : "landscape";
891 iconWidth = screenOrientation === "portrait" ? screenHeight / 4 : screenWidth / 4;
894 $(".mainButton").width(iconWidth + "px");
895 $(".mainButton").height(iconWidth + "px");
897 var iconsTop = screenOrientation === "portrait" ? ((screenHeight - (iconWidth * 3)) / 2) - (padding * 3) : (screenHeight - iconWidth) / 2;
899 if (screenOrientation === "portrait")
900 $("#mainMenuButtons").css({"top": iconsTop + "px", "left" : (screenWidth / 2) - (iconWidth /2) - padding + "px", "width" : "50%"});
903 $("#mainMenuButtons").css({"top": iconsTop + "px", "left" : ((iconWidth / 2) - (padding * 3)) + "px", "width" : "100%"});
904 $("#sortButtons").addClass("landscape");
908 function resizePlayerPage()
910 console.log("MediaPlayer in resizePlayerPage");
912 audioPlayer = document.getElementById("audioPlayer");
913 videoPlayer = document.getElementById("videoPlayer");
914 screenWidth = window.innerWidth;
915 screenHeight = window.innerHeight;
918 var buttonWidth = screenOrientation === "portrait" ? screenHeight * 0.05 : screenWidth * 0.05;
920 $("#backButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": ((screenWidth / 2) - (buttonWidth *3)) + "px"});
921 $("#nextButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": ((screenWidth / 2) + (buttonWidth *2)) + "px"});
922 $("#returnButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": padding + "px"});
923 $("#listButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": (screenWidth - buttonWidth - padding * 2) + "px"});
924 $("#playButton").css({"width": buttonWidth * 1.3 + "px", "height": buttonWidth * 1.3 + "px", "top": padding * 0.3 + "px", "left": (screenWidth / 2) - (buttonWidth / 2) + "px"});
926 mediaNameCanvas.width = (screenWidth);
927 mediaNameCanvas.height = (screenHeight * 0.34) - (buttonWidth + (2 * padding));
928 mediaNameCanvas.style.top = (buttonWidth + (2 * padding) ) + "px";
929 mediaNameCanvas.style.left = "0px";
931 var sortButtonTop = (buttonWidth + (2 * padding) ) + mediaNameCanvas.height - (buttonWidth * 1.3);
932 var sortButtonWidth = buttonWidth * 2.5;
933 var buttonSpacing = screenWidth / 5;
935 mediaListItemW = $("#mediaList").width() * 0.92;
936 mediaListItemH = $("#mediaList").height() / 10;
941 console.log("MediaPlayer in resizeAll");
947 * swipe - Handles swipe events. Currently it just acts as another way to hit the next / back buttons, but
948 * it could be expanded to other things in the future.
951 function swipe(direction, object)
953 console.log("MediaPlayer in swipe");
957 if (direction === "right")
959 else if (direction === "left")
970 console.log("MediaPlayer in init");
971 var vehicle = tizen.vehicle;
973 vehicle.subscribe("NightMode",function(value) {
974 console.log("MediaPlayer: Day / Night mode changed to " + value.nightmode);
976 if (nightMode !== value.nightmode)
978 Array.prototype.forEach.call (document.querySelectorAll ('*'), function (el) {el.classList.toggle('night');});
979 nightMode = value.nightmode
983 musicIcon.src = "images/musicIcon.png";
984 vidIcon.src = "images/videoIcon.png";
985 imgIcon.src = "images/imageIcon.png";
986 imageControls = new ImageControls();
988 mediaNameCanvas = document.getElementById("mediaName");
989 mediaNameCTX = mediaNameCanvas.getContext("2d");
991 //Resize all items and search for local media
994 //Check if DLNA plugin is installed. If so, scan for media.
995 if (tizen.mediaserver)
997 tizen.mediaserver.scanNetwork(foundMediaServer);
1000 console.log("MediaPlayer: No DLNA server running, using local media only...");
1002 //Setup voice control
1006 getMedia(contentType);
1008 //Prevent highlighting
1009 window.ondragstart = function() { return false; }
1011 $(window).bind('resize', resizeAll);
1013 //Simple swipe detection
1014 $("#mediaName").mousedown(function(e){mouseDownEvent = e;});
1015 $("#mediaName").mouseup(function(e){
1016 if (Math.abs(mouseDownEvent.clientY - e.clientY) < 100)
1018 if (Math.abs(mouseDownEvent.clientX - e.clientX) > 100)
1020 if (mouseDownEvent.clientX > e.clientX)
1021 swipe("left", "mediaName");
1023 swipe("right", "mediaName");
1028 document.getElementById('videoPlayer').addEventListener("playing", function() {
1029 $("#navigationButtons").hide();
1031 document.getElementById('videoPlayer').addEventListener("pause", function() {
1032 $("#navigationButtons").show();
1036 $(document).ready(function () {