Adding back in tizen.vehicle reference. Also adding a check for which menu should...
[profile/ivi/MediaPlayer.git] / js / dlna.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 var stopConnectionSearch = undefined;
10 var remoteMediaPreviouslyLoaded = false;
11
12 function convertMediaServerContent(item)
13 {
14         console.log(">>> MediaObject2 >>> " + JSON.stringify(item));
15         var content = { id: item.Path, title: item.DisplayName };
16
17         if (item.Type.indexOf("container") == 0)
18         {
19                 content.directoryURI = "";
20                 content.storageType = "EXTERNAL";
21         }
22
23         else
24         {
25                 content.editableAttributes = [];
26                 content.name = content.title;
27                 content.contentURI = item.URLs[0];
28                 content.mimeType = item.MIMEType;
29                 content.size = item.Size;
30                 content.rating = 0;
31                 content.remoteFile = true;
32
33                 if (item.Type.indexOf("video") == 0)
34                 {
35                         content.type = "VIDEO";
36                         content.artists = new Array();
37                         content.artists[0] = "Unknown";
38                         content.duration = item.Duration;
39                         content.width = item.Width;
40                         content.height = item.Height;
41                 }
42
43                 else if (item.Type.indexOf("audio") == 0 ||
44                 item.Type.indexOf("music") == 0)
45                 {
46                         content.type = "AUDIO";
47                         content.album = item.Album ? item.Album : "Unknown";
48                         content.coverArt = musicIcon;
49                         content.artists = new Array();
50                         content.artists[0] = item.Artist ? item.Artist : "Unknown";
51                         content.bitrate = item.SampleRate;
52                         content.duration = item.Duration;
53                 }
54
55                 if (item.Type.indexOf("image") == 0)
56                 {
57                         content.type = "IMAGE";
58                         content.width = item.Width;
59                         content.height = item.Height;
60                         content.orientation = "NORMAL";
61                 }
62         }
63
64         return content;
65 }
66
67 function browseCallback(medias)
68 {
69         console.log("MediaPlayer: MediaServer has called browseCallback");
70         console.log("found " + medias.length + " medias.");
71
72         for (var i=0; i<medias.length; i++)
73                 convertMediaServerContent(medias[i]);
74 }
75
76 function findAllCallback(medias)
77 {
78         console.log("MediaServer findAllCallback");
79         console.log("found " + medias.length + " medias.");
80
81         clearInterval(stopConnectionSearch);
82         stopConnectionSearch = undefined;
83
84         var itemsAdded = 0;
85         var audioContent = new Array();
86         var videoContent = new Array();
87         var imageContent = new Array();
88
89         for (var i=0; i < medias.length; i++)
90         {
91                 var current = convertMediaServerContent(medias[i]);
92
93                 if (current)
94                 {
95                         switch(current.type)
96                         {
97                                 case "AUDIO":
98                                         audioContent.push(current);
99                                         itemsAdded += 1;
100                                         break;
101                                 case "VIDEO":
102                                         videoContent.push(current);
103                                         itemsAdded += 1;
104                                         break;
105                                 case "IMAGE":
106                                         imageContent.push(current);
107                                         itemsAdded += 1;
108                                         break;
109                                 default:
110                         }
111                 }
112         }
113
114         //Force MediaPlayer to reload the lists so the new items show
115         audioMediaListLoaded = false;
116         videoMediaListLoaded = false;
117         imageMediaListLoaded = false;
118
119         audioPlayer.updateContent(audioContent, true);
120         videoPlayer.updateContent(videoContent, true);
121         imagePlayer.updateContent(imageContent, true);
122 }
123
124 function foundMediaServer(srv)
125 {
126         console.log("MediaPlayer: New MediaServer Found");
127         console.log("MediaServer id: " + srv.id);
128         console.log("MediaServer friendlyName: " + srv.friendlyName);
129
130         clearInterval(stopServerSearch);
131
132         if (srv.root)
133         {
134                 console.log("MediaPlayer: MediaServer root folder: " + srv.root.id);
135                 srv.browse(srv.root.id, "+DisplayName", 0, 0, browseCallback);
136                 srv.find(srv.root.id, "*", "+DisplayName", 0, 0, findAllCallback);
137
138         // Removing this for now to keep from spamming.  Note Rygel must be running when launched or it will never find it
139         //      if (stopConnectionSearch !== undefined)
140         //              clearInterval(stopConnectionSearch);
141
142         //      stopConnectionSearch = setInterval(function(){console.log("MediaPlayer searching for remote media..."); tizen.mediaserver.scanNetwork(foundMediaServer);}, 3000);
143
144         }
145         else
146                 console.log("MediaServer not browsable");
147 }