Samsung Electronics logo

Transferring Content

Table of Contents


Transferring Content

This section describes how to transfer content using Wi-Fi.

To transfer content between media providers, you can use the receive() methods of the provider. Provider works only when devices are connected to each other in Wi-Fi.

receive() requires items as input parameters. MediaReceiverEventCallback captures events that occur when transferring items. receive() can complete different functions with different input parameters.

Possible input item values are listed below:

Input Item Description
var item; Retrieves an item from a remote provider.

var url = " file://Videos/clip.mp4";

var mediaContent = new Item(url, "video/mp4", "Local Video Clip");

Creates an item with local content.

var url = " http://mediashare.com/videos/clip.mp4";

var mediaContent = new Item(url, "video/mp4", "WebVideo Clip");

Creates an item with Web content.

Uploading Item

If you want to upload an item to or from the other media provider, you can use the item object which has retrieved as the first input parameter. The sample code is as follows:

 
// Below is assumed that a provider object is retrieved properly. 
// For further details, see the getDevice().
var provider; 

// Define success callback for receive.
function receiverSCB(sessionId) {
	console.log("download: " + sessionId);
}

// Define error callback
function receiverECB(error, sessionId) {
	console.log(error.message);
}

// Define event listener.
var eventListener = {
	oncompleted: function (sessionId) { 
		console.log("uploading/downloading " + sessionId + " is completed."); 
	},
	onprogressUpdated: function (sessionId, receivedSize, totalSize) {
		console.log("uploading/downloading " + sessionId + " is progressing : " + receivedSize + " / " + totalSize); 
	}
};

// Identify the item to be uploaded here

var item; // it is assumed that this item will be uploaded. 

try {
	var receiver = provider. getMediaReceiver();
	if (receiver) {
		// Upload the item to the destination provider.
		var sessionID = receiver.receive(item, receiverSCB, receiverECB, eventListener);
	}
} catch (e) {
	console.log(e.name);
}
			

Transferring Local / Internet Content

receive() does not only upload an item to another DMS, but it also transfer a local file or internet content to other media providers.

Firstly, If you want to transfer local content to another DMS, you must create an item with local content. The sample code is as follows:

 
var provider; // it is assumed that a provider object is retrieved properly. For further details, see the getDevice().

// Define success callback for receive.
function receiverSCB(sessionId) {
	console.log("download session : " + sessionId);
}

// Define error callback
function receiverECB(error, sessionId) {
	console.log(error.message);
}

// Define event listener.
var eventListener = {
	oncompleted: function (sessionId) { 
		console.log("transferring " + sessionId + " is completed."); 
	},
	onprogressUpdated: function (sessionId, receivedSize, totalSize) {
		console.log("transferring " + sessionId + " is progressing : " + receivedSize + " / " + totalSize); 
	}
}

// Identify the item to be transferred.
var url = "file://Videos/clip.mp4"; // it is assumed that the URL of a local content is stored. 
var mimeType = "video/mp4";
var mediaContent = new Item(url, mimeType, "Local Video Clip");

try {
	var receiver = provider.getMediaReceiver();
	if (receiver) {
		// transfer the local content item to destination provider.
		var sessionId = receiver.receive(mediaContent, receiverSCB, receiverECB, eventListener);
	}
} catch (e) {
	console.log(e.name);
}
				

Correspondingly, if you want to transfer Web content to other providers, you must create an item with Web content.

You can transfer Web content to another DMS as follows:

 
// it is assumed that a provider object is retrieved properly. 
// For further details, see the getDevice().				
var provider; 

//Define success callback for receive.
function receiverSCB(sessionId) {
    console.log("download: " + sessionId);
}

// Define error callback
function receiverECB(error, sessionId) {
    console.log(error.message);
}

// Define event listener.
var eventListener = {
    oncompleted: function (sessionId) { 
        console.log("transferring " + sessionId + " is completed."); 
    },
    onprogressupdated: function (sessionId, receivedSize, totalSize) {
        console.log("transferring " + sessionId + " is progressing : " + receivedSize + " / " + totalSize); 
    }
};

// Identify the item to be transferred.
var url = "http://mediashare.com/videos/clip.mp4"; // it is assumed that the URL of a web content is stored. 
var mimeType = "video/mp4";
var mediaContent = new Item(url, mimeType, "Web Video Clip");

try {
    var receiver = provider.getMediaReceiver();
    if (receiver) {
        // transfer the web item.
        var sessionId = receiver.receive(mediaContent, receiverSCB, receiverECB, eventListener);
    }
} catch (e) {
    console.log(e.name);
}