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