Adding back in tizen.vehicle reference. Also adding a check for which menu should...
[profile/ivi/MediaPlayer.git] / js / main.js
1 /*
2  * Copyright (c) 2013, Intel Corporation.
3  *
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
7  *
8  */
9
10 var currentMenu = "main";
11 var mouseDownEvent;
12 var resizeCB = resizeMainMenu;
13 var screenWidth;
14 var screenHeight;
15 var screenOrientation;
16 var iconWidth;
17 var padding;
18 var contentType = "AUDIO";
19 var currentPlayer;
20 var currentMediaList = $("#audioMediaList");
21 var audioMediaListLoaded = false;
22 var videoMediaListLoaded = false;
23 var imageMediaListLoaded = false;
24 var audioPlayer;
25 var videoPlayer;
26 var imagePlayer;
27 var vidIcon = new Image();
28 var imgIcon = new Image();
29 var musicIcon = new Image();
30 var imagesLoaded = false;
31 var mediaListItemW;
32 var mediaListItemH;
33 var playOnConnect = false;
34 var mediaNameCanvas;
35 var mediaNameCTX;
36 var trackTimeCanvas;
37 var trackTimeCTX;
38 var speechObj;
39 var nightMode = false;
40 var waitingToResumeVideo = false;               //Media has been paused by exterior forces.  If set to true, resume previous media when given the signal.
41 var stopServerSearch;
42 var playBarHeight;
43 var boxWidth;
44 var textStartX;
45 var remoteMediaSearchAttempts = 0;
46
47 var mainMenuTitleTemplateLandscape = {"font" : "oblique bolder 18pt arial", "lineWidth" : 6.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
48                 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.4)"};
49
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)"};
52
53 var mainTrackTemplateLandscape = {"font" : "bold 16pt Arial", "lineWidth" : 4.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
54                 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
55
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))"};
58
59 var timeTemplate = {"font" : "bold 25pt Arial", "lineWidth" : 7.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
60                 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
61
62 var timeTemplateLandscape = {"font" : "bold 6pt Arial", "lineWidth" : 3.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "left",
63                 "largeShadow" : 8, "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 45, "shadowColor" : "rgba(255, 187, 0, 0.5))"};
64
65 var mediaTextTemplate2 = {"font" : "bold 20pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
66                 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
67
68 var mediaTextTemplate3 = {"font" : "bold 20pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
69
70 var trackTextTemplate  = {"font" : "bold 16pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
71
72 var mediaTextTemplate2Landscape = {"font" : "bold 13pt Arial", "lineWidth" : 10.0, "fillStyle" : "white", "strokeStyle" : "rgba(0, 0, 0, 1.0)", "textAlign" : "left",
73                 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 0, "shadowColor" : "rgba(0, 0, 0, 1.0)"};
74
75 var mediaTextTemplate3Landscape = {"font" : "bold 13pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "rgba(100, 0, 0, 1.0)", "textAlign" : "left"};
76
77 var trackTextTemplateLandscape  = {"font" : "bold 11pt Arial", "lineWidth" : 3.0, "fillStyle" : "white", "strokeStyle" : "black", "textAlign" : "left"};
78
79
80 var mediaTextTemplate = {"font" : "bold 20pt Arial", "fillStyle" : "", "textAlign" : "left",
81                 "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 12, "shadowColor" : "red"};
82
83 function onError()
84 {
85         console.log("Content discovery failed");
86 }
87
88 function setupSpeech()
89 {
90         console.log("MediaPlayer in setupSpeech");
91
92         speechObj = tizen.speech;
93         speechObj.vocalizeString(" ");
94
95         try
96         {
97                 var speechEventListener = {
98                         onaudiostart: function(){console.log("MediaPlayer: onaudiostart received");},
99                         onsoundstart: function(){console.log("MediaPlayer: onsoundstart received");},
100                         onspeechstart: function(){console.log("MediaPlayer: onspeechstart received");},
101                         onspeechend: function(){console.log("MediaPlayer: onspeechend received");},
102                         onsoundend: function(){console.log("MediaPlayer: onsoundend received");},
103                         onaudioend: function(){console.log("MediaPlayer: onaudioend received");},
104                         onresult: function(result){
105
106                                 console.log("MediaPlayer: onresult received");
107
108                                 for (var i = 0; i < result.length; i++)
109                                 {
110                                         console.log("MediaPlayer: forloop, command = " + result[i]);
111                                         var commandFound = false;
112
113                                         switch(result[i])
114                                         {
115                                                 case "play":
116                                                         playButtonClick();
117                                                         commandFound = true;
118                                                 break;
119                                                 case "next":
120                                                         nextButtonClick();
121                                                         commandFound = true;
122                                                 break;
123                                                 case "previous":
124                                                         backButtonClick();
125                                                         commandFound = true;
126                                                 break;
127                                                 case "stop":
128                                                 case "pause":
129                                                         pauseButtonClick();
130                                                         commandFound = true;
131                                                 break;
132                                                 default:
133                                                 break;
134                                         }
135
136                                         if (commandFound)
137                                                 break;
138                                 }
139                         },
140                         onnomatch: function(result){console.log("MediaPlayer: onnomatch received ");},
141                         onerror: function(error){console.log("MediaPlayer: onerror received");},
142                         onstart: function(){console.log("MediaPlayer: onstart received");},
143                         onend: function(){console.log("MediaPlayer: onend received");}
144                 }
145
146                 speechObj.setCBListener(speechEventListener);
147
148         }
149         catch(err)
150         {
151                 console.log("MediaPlayer setupSpeech FAILED + " + err.message);
152         }
153
154 }
155
156 function onAudioContentLoaded(newContent)
157 {
158         if (!newContent || newContent.length === 0)
159         {
160                 console.log("MediaPlayer: some content failed to load, trying again for " + audioPlayer.type);
161                 audioPlayer.clearContent();
162                 setTimeout(function(){getMedia(onAudioContentLoaded, "AUDIO");}, 3000);
163                 return;
164         }
165         else
166         {
167                 audioPlayer.updateContent(newContent, true);
168                 audioPlayer.onContentLoaded();
169         }
170 }
171
172 function onVideoContentLoaded(newContent)
173 {
174         if (!newContent || newContent.length === 0)
175         {
176                 console.log("MediaPlayer: some content failed to load, trying again for " + videoPlayer.type);
177                 videoPlayer.clearContent();
178                 setTimeout(function(){getMedia(onVideoContentLoaded, "VIDEO");}, 3000);
179                 return;
180         }
181         else
182         {
183                 videoPlayer.updateContent(newContent, true);
184                 videoPlayer.onContentLoaded();
185         }
186 }
187
188 function onImageContentLoaded(newContent)
189 {
190         if (!newContent || newContent.length === 0)
191         {
192                 console.log("MediaPlayer: some content failed to load, trying again for " + imagePlayer.type);
193                 imagePlayer.clearContent();
194                 setTimeout(function(){getMedia(onImageContentLoaded, "IMAGE");}, 3000);
195                 return;
196         }
197         else
198         {
199                 imagePlayer.updateContent(newContent, true);
200                 imagePlayer.onContentLoaded();
201         }
202 }
203
204 function getMedia(callback, filterType)
205 {
206         console.log("MediaPlayer in getMedia");
207         var manager = tizen.content;
208         if (manager)
209         {
210                 var filter = new tizen.AttributeFilter("type", "EXACTLY", filterType);
211                 manager.find(callback, onError, null, filter);
212         }
213         else
214                 console.log("MediaPlayer failed to receive media, tizen.content is unavailable");
215 }
216
217 function showMediaMenu()
218 {
219         console.log("MediaPlayer in showMediaMenu");
220         $(".navButton").show();
221
222         switch(currentPlayer.type)
223         {
224                 case "audio":
225                         $("#mediaName").show();
226                         $("#trackTime").show();
227                         $(".sortButton").show();
228                         currentPlayer.show();
229
230                         if (screenOrientation === "landscape" )
231                                 $("#audioMediaList").addClass("landscape");
232                         else
233                                 $("#audioMediaList").removeClass("landscape");
234
235                         $("#audioMediaList").show();
236                         break;
237
238                 case "video":
239                         //show video
240                         currentPlayer.show();
241                         //setTimeout(function(){currentPlayer.show()}, 800);            //The video element can't be faded, so wait a moment before showing
242                         break;
243
244                 case "image":
245                         //show image
246                         currentPlayer.show();
247                         break;
248
249                 default:
250                         console.log("Invalid player type");
251                 break;
252         }
253 }
254
255 function showMediaList()
256 {
257         console.log("MediaPlayer in showMediaList");
258
259         if (currentMediaList.is(":visible"))
260                 currentMediaList.hide();
261         else
262         {
263                 currentMediaList.show();
264         }
265 }
266
267 function changeMenu(menuButtonId)
268 {
269         console.log("MediaPlayer in changeMenu");
270         var clickedButton  = $("#" + menuButtonId);
271         var buttonWidth  = clickedButton.width();
272         var buttonHeight = clickedButton.height();
273         var buttonBottom = clickedButton.css("bottom");
274         var buttonRight  = clickedButton.css("right");
275
276 /*
277         //Animate the clicked button slightly
278         clickedButton.animate({
279                 bottom: screenOrientation === "portrait" ? "+=0" : "+=50",
280                                 right: screenOrientation === "portrait" ? "+=50" : "+=0",
281                                                 opacity: "0"
282         }, 300 ,
283
284         //Reset the size once done
285         function() {
286                 clickedButton.width(buttonWidth);
287                 clickedButton.height(buttonHeight);
288
289                 if (screenOrientation === "portrait")
290                         clickedButton.css({"right": buttonRight});
291                 else
292                         clickedButton.css({"bottom": buttonBottom});
293         }
294         );
295 */
296         $(".mainButton").hide();
297
298         switch(menuButtonId)
299         {
300                 case ("mainMusicButton"):
301                         speechObj.vocalizeString("Music player");
302                         currentMenu = "audio";
303                         currentPlayer = audioPlayer;
304                         currentMediaList = $("#audioMediaList");
305                         localStorage.prevMenu = "mainMusicButton";
306
307                         if (audioPlayer.currentAudioContent && audioPlayer.currentAudioContent.contentURI)
308                         {
309                                 localStorage.prevAudioTrack = audioPlayer.currentAudioContent.contentURI
310                                 localStorage.prevAudioTime = audioPlayer.playerControls.currentTime;
311                         }
312
313                         localStorage.prevVideo = undefined;
314                         localStorage.prevVideoTime = undefined;
315
316                         if (!audioMediaListLoaded)
317                                 audioPlayer.fillMediaList();
318
319                         showMediaMenu();
320                 break;
321
322                 case ("mainVideoButton"):
323                         speechObj.vocalizeString("Video player");
324                         currentMenu = "video";
325                         currentPlayer = videoPlayer;
326                         currentMediaList = $("#videoMediaList");
327                         localStorage.prevMenu = "mainVideoButton";
328
329                         if (videoPlayer.currentVideoContent && videoPlayer.currentVideoContent.contentURI)
330                         {
331                                 localStorage.prevVideo = videoPlayer.currentVideoContent.contentURI
332                                 localStorage.prevVideoTime = videoPlayer.playerControls.currentTime;
333                         }
334
335                         localStorage.prevAudioTime = undefined;
336                         localStorage.prevAudioTrack = undefined;
337
338                         if (!videoMediaListLoaded)
339                                 videoPlayer.fillMediaList();
340
341                         showMediaMenu();
342                 break;
343
344                 case ("mainImageButton"):
345                         speechObj.vocalizeString("Picture viewer");
346                         currentMenu = "image";
347                         currentPlayer = imagePlayer;
348                         currentMediaList = $("#imageMediaList");
349                         localStorage.prevMenu = "mainImageButton";
350
351                         if (!imageMediaListLoaded)
352                                 imagePlayer.fillMediaList();
353
354                         showMediaMenu();
355                 break;
356                 default:
357                         console.log("Error: No menu by that name");
358                 break;
359         }
360 }
361
362 function showMainMenu()
363 {
364         console.log("MediaPlayer in showMainMenu, clearing all localStorage...");
365         currentMenu = "main";
366         delete localStorage.prevMenu;
367         localStorage.prevAudioTime = undefined;
368         localStorage.prevAudioTrack = undefined;
369         localStorage.prevVideo = undefined;
370         localStorage.prevVideoTime = undefined;
371         localStorage.prevImage = undefined;
372
373         currentPlayer.pause();
374
375         //If the media list is showing, hide it.  Remove the mediaListAudioList class if it exists so that it will resize properly
376         if (currentMediaList.is(":visible"))
377                 currentMediaList.hide();
378
379         $(".navButton").hide();
380         $(".sortButton").hide();
381         $("#mediaName").hide();
382         $("#trackTime").hide();
383         $(".player").hide();
384         $(".mainButton").css({"opacity": "100"});
385         $(".mainButton").show();
386 }
387
388 function sortByAlpha(contentToSort)
389 {
390         currentPlayer.sortByAlpha();
391 }
392
393 function sortByArtist(contentToSort)
394 {
395         currentPlayer.sortByArtist();
396 }
397
398 function sortByAlbum(contentToSort)
399 {
400         currentPlayer.sortByAlbum();
401 }
402
403 /**************************************** NAVIGATION FUNCTIONS *******************************************/
404
405 // This function is called once a file being loaded is ready to play
406 function playLoadedMedia()
407 {
408         audioPlayer.playLoadedMedia();
409 }
410
411 function videoLoaded()
412 {
413     videoPlayer.videoLoaded();
414 }
415
416 function playButtonClick()
417 {
418         console.log("MediaPlayer in playButtonClick");
419         if (!currentPlayer.playing())
420                 currentPlayer.play();
421         else
422                 currentPlayer.pause();
423 }
424
425 function pauseButtonClick()
426 {
427         console.log("MediaPlayer in pauseButtonClick");
428         if (currentPlayer.playing())
429         {
430                 currentPlayer.pause();
431         }
432 }
433
434 function backButtonClick()
435 {
436         console.log("MediaPlayer in backButtonClick");
437         currentPlayer.previous();
438 }
439
440
441 function nextButtonClick()
442 {
443         console.log("MediaPlayer in nextButtonClick");
444         currentPlayer.next();
445 }
446
447 /**************************************** END NAVIGATION FUNCTIONS *******************************************/
448
449 function resizeMainMenu()
450 {
451         console.log("MediaPlayer in resizeMainMenu");
452
453         currentMediaList.hide();
454         screenWidth = window.innerWidth;
455         screenHeight = window.innerHeight;
456         screenOrientation = screenWidth < screenHeight ? "portrait" : "landscape";
457         iconWidth = screenOrientation === "portrait" ? screenHeight / 4 : screenWidth / 4;
458         var padding = 20;
459
460         $(".mainButton").width(iconWidth + "px");
461         $(".mainButton").height(iconWidth + "px");
462
463         var iconsTop  = screenOrientation === "portrait" ? ((screenHeight - (iconWidth * 3)) / 2) - (padding * 3) : (screenHeight - iconWidth) / 2;
464
465         if (screenOrientation === "portrait")
466                 $("#mainMenuButtons").css({"top": iconsTop + "px", "left" : (screenWidth / 2) - (iconWidth /2) - padding + "px", "width" : "50%"});
467         else
468         {
469                 $("#mainMenuButtons").css({"top": iconsTop + "px", "left" : ((iconWidth / 2) - (padding * 3)) + "px", "width" : "100%"});
470                 $("#sortButtons").addClass("landscape");
471         }
472 }
473
474 function resizePlayerPage()
475 {
476         console.log("MediaPlayer in resizePlayerPage");
477
478         screenWidth = window.innerWidth;
479         screenHeight = window.innerHeight;
480
481         var padding = 15;
482         var buttonWidth = screenOrientation === "portrait" ? screenHeight * 0.05 : screenWidth * 0.05;
483
484         $("#backButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": ((screenWidth / 2) - (buttonWidth *3)) + "px"});
485         $("#nextButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": ((screenWidth / 2) + (buttonWidth *2)) + "px"});
486         $("#returnButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": padding + "px"});
487         $("#listButton").css({"width": buttonWidth + "px", "height": buttonWidth + "px", "top": padding + "px", "left": (screenWidth - buttonWidth - padding * 2) + "px"});
488         $("#playButton").css({"width": buttonWidth * 1.15 + "px", "height": buttonWidth * 1.15 + "px", "top": padding * 0.3 + "px", "left": (screenWidth / 2) - (buttonWidth / 2) + "px"});
489
490         trackTimeCanvas.width = mediaNameCanvas.width = (screenWidth);
491         trackTimeCanvas.height = mediaNameCanvas.height = (screenHeight * 0.34) - (buttonWidth + (2 * padding));
492         trackTimeCanvas.style.top = mediaNameCanvas.style.top = (buttonWidth + (2 * padding) ) + "px";
493         trackTimeCanvas.style.left = mediaNameCanvas.style.left = "0px";
494
495         var sortButtonTop = (buttonWidth + (2 * padding) ) + mediaNameCanvas.height - (buttonWidth * 1.3);
496         var sortButtonWidth = buttonWidth * 2.5;
497         var buttonSpacing = screenWidth / 5;
498
499         mediaListItemW = $("#videoMediaList").width() * 0.92;
500         mediaListItemH = $("#videoMediaList").height() / 10;
501 }
502
503 function resizeAll()
504 {
505         console.log("MediaPlayer in resizeAll");
506         resizeMainMenu();
507         resizePlayerPage();
508 }
509
510 /*
511  * swipe - Handles swipe events.  Currently it just acts as another way to hit the next / back buttons, but
512  * it could be expanded to other things in the future.
513  */
514
515 function swipe(direction, object)
516 {
517         console.log("MediaPlayer in swipe");
518         switch (object)
519         {
520         case "mediaName":
521                 if (direction === "right")
522                         nextButtonClick();
523                 else if (direction === "left")
524                         backButtonClick();
525                 break;
526
527         default:
528                 break;
529         }
530 }
531
532 function toggleNightMode(nightModeValue)
533 {
534         if (nightMode !== nightModeValue)
535         {
536                 Array.prototype.forEach.call (document.querySelectorAll ('*'), function (el) {el.classList.toggle('night');});
537                 nightMode = nightModeValue;
538         }
539 }
540
541 function init()
542 {
543         console.log("MediaPlayer in init");
544
545         musicIcon.src = "images/musicIcon.png";
546         vidIcon.src = "images/videoIcon.png";
547         imgIcon.src = "images/imageIcon.png";
548         mediaNameCanvas = document.getElementById("mediaName");
549         mediaNameCTX = mediaNameCanvas.getContext("2d");
550         trackTimeCanvas = document.getElementById("trackTime");
551         trackTimeCTX = trackTimeCanvas.getContext("2d");
552         playBarHeight = mediaNameCanvas.height;
553         boxWidth = playBarHeight * 0.75;
554         textStartX = boxWidth + 50;
555
556         var vehicle = tizen.vehicle;
557
558
559         /* Subscribe to AMB NightMode signal, and switch colors
560          * upon receipt of the signal
561          */
562
563         if (vehicle && vehicle !== undefined)
564         {
565                 var getVal = vehicle.get("NightMode");
566
567                 //Check that NightMode returned a value before trying to hook up to it
568                 if (getVal)
569                 {
570                         toggleNightMode(getVal.nightMode);
571                 }
572
573                 /* Subscribe to AMB NightMode signal, and switch colors
574                 * upon receipt of the signal
575                 */
576
577                 vehicle.subscribe("NightMode",function(value) {
578                                 console.log("MediaPlayer: Day / Night mode changed to " + value.nightMode);
579                                 toggleNightMode(value.nightMode);
580                 });
581
582
583                 /* Subscribe to AMB DrivingMode signal, and pause video
584                  * upon receipt of the signal
585                  */
586
587
588                 vehicle.subscribe("DrivingMode",function(value) {
589                         console.log("MediaPlayer: DrivingMode changed to " + value.drivingMode);
590
591                         if (value.drivingMode > 0 && currentPlayer.type === "video" && currentPlayer.playing())
592                         {
593                                 console.log("MediaPlayer: pausing video due to vehicle motion");
594                                 currentPlayer.pause();
595                                 waitingToResumeVideo = true;
596                         }
597                         else if (value.drivingMode === 0 && currentPlayer.type === "video" && waitingToResumeVideo)
598                         {
599                                 console.log("MediaPlayer: vehicle has stopped, resuming video");
600                                 currentPlayer.play();
601                                 waitingToResumeVideo = false;
602                         }
603                 });
604         }
605
606         //Setup voice control
607         if (tizen.speech)
608                 setupSpeech();
609         else {
610                 console.log("MediaPlayer: Speech Recognition not running, voice control will be unavailable");
611                 speechObj = {
612                     vocalizeString: function(item) { console.log(item); }
613                 };
614         }
615
616         audioPlayer = new MediaPlayer("audio");
617         videoPlayer = new MediaPlayer("video");
618         imagePlayer = new MediaPlayer("image");
619         currentPlayer = audioPlayer;
620
621         //Resize all items and search for local media
622         resizeAll();
623
624         if (localStorage.prevMenu && localStorage.prevMenu !== undefined && localStorage.prevMenu !== "MAIN")
625                 changeMenu(localStorage.prevMenu)
626         else
627                 showMainMenu();
628
629         getMedia(onAudioContentLoaded, "AUDIO");
630         getMedia(onVideoContentLoaded, "VIDEO");
631         getMedia(onImageContentLoaded, "IMAGE");
632
633         //Check if DLNA plugin is installed.  If so, scan for media.
634         if (tizen.mediaserver)
635         {
636                 //Currently no success signal, so continue trying until a server is found.  Once that
637                 //happens, clear the stopServerSearch interval
638
639                 stopServerSearch = setInterval(function(){
640                                                                 console.log("MediaPlayer searching for remote media...");
641                                                                 if (remoteMediaSearchAttempts < 5)
642                                                                         tizen.mediaserver.scanNetwork(foundMediaServer);
643                                                                 else
644                                                                         clearInterval(stopServerSearch);
645                                                                 remoteMediaSearchAttempts++;
646                                                          }, 5000);
647         }
648         else
649                 console.log("MediaPlayer: No DLNA server running, using local media only...");
650
651         //Prevent highlighting
652         window.ondragstart = function() { return false; }
653
654         $(window).bind('resize', resizeAll);
655
656         //Simple swipe detection
657         $("#mediaName").mousedown(function(e){mouseDownEvent = e;});
658         $("#mediaName").mouseup(function(e){
659                 if (Math.abs(mouseDownEvent.clientY - e.clientY) < 100)
660                 {
661                         if (Math.abs(mouseDownEvent.clientX - e.clientX) > 100)
662                         {
663                                 if (mouseDownEvent.clientX > e.clientX)
664                                         swipe("left", "mediaName");
665                                 else
666                                         swipe("right", "mediaName");
667                         }
668                 }
669         });
670
671     document.getElementById('videoPlayer').addEventListener("playing", function() {
672         $("#playButton").toggleClass('playing', true);
673         $("#navigationButtons").hide();
674     }, false);
675     document.getElementById('videoPlayer').addEventListener("pause", function() {
676         $("#playButton").toggleClass('playing', false);
677         $("#navigationButtons").show();
678     }, false);
679     document.getElementById('videoPlayer').addEventListener("ended", function() {
680         $("#playButton").toggleClass('playing', false);
681         $("#navigationButtons").show();
682     }, false);
683     document.getElementById('audioPlayer').addEventListener("playing", function() {
684         $("#playButton").toggleClass('playing', true);
685     }, false);
686     document.getElementById('audioPlayer').addEventListener("pause", function() {
687         $("#playButton").toggleClass('playing', false);
688     }, false);
689     document.getElementById('audioPlayer').addEventListener("ended", function() {
690         $("#playButton").toggleClass('playing', false);
691     }, false);
692     document.getElementById('imagePlayer').addEventListener("click", function() {
693         if (!imagePlayer.playing)
694         {
695             // next picture
696             nextButtonClick();
697         }
698         else
699         {
700             // pause the slideshow and fade in the controls
701             imagePlayer.pause();
702             $("#navigationButtons").show();
703         }
704     }, false);
705 }
706
707 $(document).ready(function () {
708         init();
709 });