Update Modello web samples from upstream; version up
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / MediaPlayer / project / js / listFunctions.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 function mediaError()
11 {
12     console.log("MediaPlayer: file failed to load");
13 }
14
15 var drawCanvasImage = function(imageSrc)
16 {
17     return function()
18     {
19         drawAlbumArt(imageSrc);
20     }
21 }
22
23 function drawAlbumArt(imageSrc)
24 {
25     var canvasH = mediaListItemH * 0.95 ;
26     var audioContent = audioPlayer.getContent();
27
28     for (var i=0; i < audioContent.length; i++)
29     {
30         if (audioContent[i].coverArt.src !== musicIcon.src && audioContent[i].coverArt.src === imageSrc)
31         {
32             try
33             {
34                 if (i === audioPlayer.currentIndex())
35                 {
36                     audioPlayer.updateMediaName(audioContent[audioPlayer.currentIndex()].artists[0], audioContent[audioPlayer.currentIndex()].title, audioContent[audioPlayer.currentIndex()].coverArt);
37                 }
38
39                 if(audioContent[i].ctx)
40                     audioContent[i].ctx.drawImage(audioContent[i].coverArt, 0, 0, canvasH, canvasH);
41             }
42             catch(err)
43             {
44                 console.log("MediaPlayer: drawImage failed - " + err);
45             }
46         }
47     }
48 }
49
50 function loadImages()
51 {
52     console.log("MediaPlayer in loadImages");
53
54     var audioContent = audioPlayer.getContent();
55
56     for (var src in audioContent)
57     {
58         try
59         {
60             var imgSrc = (audioContent[src].coverArtURI !== undefined && audioContent[src].coverArtURI !== "") ? audioContent[src].coverArtURI : "images/musicIcon.png";
61             audioContent[src].coverArt = new Image();
62             audioContent[src].coverArt.onload = drawCanvasImage(imgSrc);
63
64             audioContent[src].coverArt.onerror = function(e){
65                 audioContent[src].coverArt.src = "images/musicIcon.png";
66             };
67
68             audioContent[src].coverArt.src = imgSrc;
69         }
70         catch(err)
71         {
72             console.log("Failed to load audio cover image: " + err);
73         }
74     }
75 }