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
9 var stopConnectionSearch = undefined;
10 var remoteMediaPreviouslyLoaded = false;
12 function convertMediaServerContent(item)
14 console.log(">>> MediaObject2 >>> " + JSON.stringify(item));
15 var content = { id: item.Path, title: item.DisplayName };
17 if (item.Type.indexOf("container") == 0)
19 content.directoryURI = "";
20 content.storageType = "EXTERNAL";
25 content.editableAttributes = [];
26 content.name = content.title;
27 content.contentURI = item.URLs[0];
28 content.mimeType = item.MIMEType;
29 content.size = item.Size;
31 content.remoteFile = true;
33 if (item.Type.indexOf("video") == 0)
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;
43 else if (item.Type.indexOf("audio") == 0 ||
44 item.Type.indexOf("music") == 0)
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;
55 if (item.Type.indexOf("image") == 0)
57 content.type = "IMAGE";
58 content.width = item.Width;
59 content.height = item.Height;
60 content.orientation = "NORMAL";
67 function browseCallback(medias)
69 console.log("MediaPlayer: MediaServer has called browseCallback");
70 console.log("found " + medias.length + " medias.");
72 for (var i=0; i<medias.length; i++)
73 convertMediaServerContent(medias[i]);
76 function findAllCallback(medias)
78 console.log("MediaServer findAllCallback");
79 console.log("found " + medias.length + " medias.");
81 clearInterval(stopConnectionSearch);
82 stopConnectionSearch = undefined;
86 for (var i=0; i < medias.length; i++)
88 var current = convertMediaServerContent(medias[i]);
95 audioContent.push(current);
99 videoContent.push(current);
103 imageContent.push(current);
111 //Force MediaPlayer to reload the lists so the new items show
112 audioMediaListLoaded = false;
113 videoMediaListLoaded = false;
114 imageMediaListLoaded = false;
117 function restartMedia (medias)
119 clearInterval(stopConnectionSearch);
120 loadPrevVideo = true;
121 $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
124 function foundMediaServer(srv)
126 console.log("MediaPlayer: New MediaServer Found");
127 console.log("MediaServer id: " + srv.id);
128 console.log("MediaServer friendlyName: " + srv.friendlyName);
130 clearInterval(stopServerSearch);
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);
138 if (stopConnectionSearch !== undefined)
139 clearInterval(stopConnectionSearch);
141 stopConnectionSearch = setInterval(function(){console.log("MediaPlayer searching for remote media..."); tizen.mediaserver.scanNetwork(foundMediaServer);}, 3000);
144 console.log("MediaServer not browsable");
147 function reconnectServer(srv)
151 srv.find(srv.root.id, "*", "+DisplayName", 0, 0, restartMedia);
152 stopConnectionSearch = setInterval(function(){console.log("MediaPlayer searching for remote media for reconnect..."); tizen.mediaserver.scanNetwork(reconnectServer);}, 1000);
155 console.log("MediaServer not reloadable");