diff options
author | M. Voerman <rekordc@gmail.com> | 2015-07-29 21:33:08 +0200 |
---|---|---|
committer | M. Voerman <rekordc@gmail.com> | 2015-07-29 21:33:08 +0200 |
commit | e825edd646d561204f472bb1fe65a03f299470ae (patch) | |
tree | 0aaf0c1335951d01fa25dd8f4bab38a734756058 | |
parent | acbc708d591afa985ab223e7caf92c3aa8bc1b5f (diff) | |
download | vdr-vipclient-e825edd646d561204f472bb1fe65a03f299470ae.tar.gz vdr-vipclient-e825edd646d561204f472bb1fe65a03f299470ae.tar.bz2 |
Testing with DLNA
-rw-r--r-- | javascript/dlna.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/javascript/dlna.js b/javascript/dlna.js new file mode 100644 index 0000000..cd4bbb2 --- /dev/null +++ b/javascript/dlna.js @@ -0,0 +1,114 @@ +var cdsService; +var operationManager; +var resultData; +var resultObjects; +var Dlna_serverId; // = new Array(); + +// Load DLNA plugin into browser +function initDLNAPlugin() { + var dlnaPlugin = document.createElement("embed"); + dlnaPlugin.type = "application/x-motorola-toi-dlna"; + dlnaPlugin.setAttribute("hidden", "true"); + document.body.appendChild(dlnaPlugin); +} + +// Get mediaserver +function find_dlna() { + Dlna_serverId = toi.DlnaService.getMediaServers(); + alert(Dlna_serverId[0]); + +} + + + +// Create content directory service in order to communicate with the DMS +function setup(serverUuid) { + cdsService = toi.dlnaService.createContentDirectoryInstance(serverUuid); + operationManager = cdsService.getCdsOperationManager(); + // Register callback function + operationManager.addEventListener(operationManager.ON_OPERATION_RESULT, onOperationResult); +} + +// Callback reciever for ON_OPERATION_RESULT events +function onOperationResult(event) { + if (event.operation.state == toi.consts.ToiOperationManager.OPERATION_PENDING) { + // Wait for all objects, but it is also possible to instead show incremental results + return; + } + else if (event.operation.state == toi.consts.ToiOperationManager.OPERATION_FAILED) { + alert("DLNA operation failed."); + operationManager.releaseOperation(event.operation.id); + } + else if (event.operation.state == toi.consts.ToiOperationManager.OPERATION_COMPLETED && + event.operation.userData == "browse") { + // This is the complete result of a browse operation, get the result objects + resultObjects = new Array(); + var maxCount = 0; + // Fetch all objects + while (true) { + resultData = cdsService.getOperationObjectResult(event.operation.id, maxCount); + var objectCount = resultObjects.length; + // Store fetched objects in local array + for (var i = 0; i < resultData.objects.length; i++) { + resultObjects[objectCount + i] = + resultData.objects[i]; + } + // Break loop if all objects are fetched + if (!resultData.hasMore) { + break; + } + } + operationManager.releaseOperation(event.operation.id); + } +} + +// Initiate a browse operation on a CDS container +function browse(containerId) { + var operationId = operationManager.createOperation("browse"); + + // Create property filter which will include title and resource URL + var propertyFilter = new Array(cdsService.PROPERTY_TITLE, cdsService.PROPERTY_RES); + + // Create a sort criteria that will sort by title + var sortCriteria = new Array(); + sortCriteria[0] = cdsService.PROPERTY_TITLE; + + // Browse the given container, start with first item and get all items + cdsService.browse(operationId, containerId, propertyFilter, sortCriteria, 0, 0); + +} + +// Open an item from the resultObjects array assigned in onOperationResult() +function openItem(itemIndex) { + // Get the requested item + var item = resultObjects[itemIndex]; + var url_dlna = ""; + + // Get the value for PROPERTY_RES + for (var i = 0; i< item.properties.length; i++) { + if (item.properties[i].id == cdsService.PROPERTY_RES) { + url_dlna = item.properties[i].value; + } + } + + // Divide class string in order to find media type + var classTypes=item.objectClass.split("."); + + // Check what type item is + if (classTypes[2] == "audioItem") { + // Play the item url + try { + alert(url_dlna); +// player.open(url_dlna); +// player.play(1000); + } + catch(e) { + alert("error: " + e); + } + } + else if (classTypes[2] == "imageItem") { + // Add code to load image in browser window + } else { + alert("Item cannot be opened"); + } +} |