MediaPlayer will now remember where the user was on restart. Also able to reconnect...
[profile/ivi/MediaPlayer.git] / js / dlna.js
index 4d9242b..41fab32 100644 (file)
@@ -6,6 +6,8 @@
  * http://www.apache.org/licenses/LICENSE-2.0
  *
  */
+var stopConnectionSearch = undefined;
+var remoteMediaPreviouslyLoaded = false;
 
 function convertMediaServerContent(item)
 {
@@ -18,13 +20,16 @@ function convertMediaServerContent(item)
                content.storageType = "EXTERNAL";
        }
 
-       else {
+       else
+       {
                content.editableAttributes = [];
                content.name = content.title;
                content.contentURI = item.URLs[0];
                content.mimeType = item.MIMEType;
                content.size = item.Size;
                content.rating = 0;
+               content.remoteFile = true;
+
                if (item.Type.indexOf("video") == 0)
                {
                        content.type = "VIDEO";
@@ -73,6 +78,9 @@ function findAllCallback(medias)
        console.log("MediaServer findAllCallback");
        console.log("found " + medias.length + " medias.");
 
+       clearInterval(stopConnectionSearch);
+       stopConnectionSearch = undefined;
+
        var itemsAdded = 0;
 
        for (var i=0; i < medias.length; i++)
@@ -106,6 +114,13 @@ function findAllCallback(medias)
        imageMediaListLoaded = false;
 }
 
+function restartMedia (medias)
+{
+       clearInterval(stopConnectionSearch);
+       loadPrevVideo = true;
+       $("#videoSrc").attr("src", videoContent[videoIndex].contentURI);
+}
+
 function foundMediaServer(srv)
 {
        console.log("MediaPlayer: New MediaServer Found");
@@ -119,7 +134,23 @@ function foundMediaServer(srv)
                console.log("MediaPlayer: MediaServer root folder: " + srv.root.id);
                srv.browse(srv.root.id, "+DisplayName", 0, 0, browseCallback);
                srv.find(srv.root.id, "*", "+DisplayName", 0, 0, findAllCallback);
+
+               if (stopConnectionSearch !== undefined)
+                       clearInterval(stopConnectionSearch);
+
+               stopConnectionSearch = setInterval(function(){console.log("MediaPlayer searching for remote media..."); tizen.mediaserver.scanNetwork(foundMediaServer);}, 3000);
        }
        else
                console.log("MediaServer not browsable");
 }
+
+function reconnectServer(srv)
+{
+       if (srv.root)
+       {
+               srv.find(srv.root.id, "*", "+DisplayName", 0, 0, restartMedia);
+               stopConnectionSearch = setInterval(function(){console.log("MediaPlayer searching for remote media for reconnect..."); tizen.mediaserver.scanNetwork(reconnectServer);}, 1000);
+       }
+       else
+               console.log("MediaServer not reloadable");
+}