Samsung Electronics logo

Browsing and Searching Contents

Table of Contents


Browse Media Content from DMS

To get a content list from a media content provider, you can use browse() asynchronous methods of the Provider. browse() can get the item list from DMS by the specified starting index and count.

browse() can be used as follows:

 
var serviceProvider; 
// It is assumed that you have obtained a serviceProvider object. For further details, see 
// createServiceProvider() or getServiceProvider().

// Define browse callback
function browseCB(list, endOfItem, providerId) {
	// the item list can be retrieved here
}
 function errorCB(error, deviceId) {
	console.log(error.message);
}
 
// Define a filter to browse a video type only
var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"});

 // Define a sort mode
var mode = new webapis.SortMode("title", "ASC");
try {
	var providers = serviceProvider.getDeviceFinder().getDeviceList("MEDIAPROVIDER");
	if (providers.length > 0) {
		// Retrieves first DMS from the root folder 
		providers[0].browse(providers[0].rootFolder, 0, 10, browseCB, errorCB, filter, mode);
	}
} catch (e) {
	console.log(e.message);
} 
			

browse() requires folderItem, startIndex, requestCount, browseFilter, sortMode as input parameters.

browse() returns the requested number of items from the content list via MediaProviderSuccessCallback.

The content list starts with the index specified by the browse condition. As in the example above, the item list can be retrieved in browseCB().

Possible interfaces are listed below:

Interface Description Method/Attribute
AbstractFilter AbstractFilter is a common interface used by different types of object filters. interface AbstractFilter { };
AttributeFilter AttributeFilter represents a filter based on an object attribute.

interface AttributeFilter : AbstractFilter {

attribute DOMString attributeName;

attribute FilterMatchFlag matchFlag;

attribute any matchValue;

};

SortMode SortMode is a common interface used for sorting queried data.

interface SortMode {

attribute DOMString attributeName;

attribute SortModeOrder order;

};

Possible values of the FilterMatchFlag are listed below:

FilterMatchFlag Enumeration Description
CONTAINS Indicates that the attribute value must contain the given string (strings only - case insensitive).

Possible values of the SortModeOrder are listed below:

Item Type Enumeration Description
AUDIO Audio type of the content
FOLDER Folder type of the content
IMAGE Image type of the content
VIDEO Video type of the content

Search Media Content from DMS

To search for content with specified conditions from media content providers, you can use the search() asynchronous methods of the Provider. The search() method allows you to search content with keywords and searchFilter.

 
var serviceProvider; 
// It is assumed that you have obtained a serviceProvider object. For further details, see the 
// createServiceProvider() or getServiceProvider().
var keyword = "foo"; 

//Define browse callback
function searchCB(list, endOfItem, providerId) {
// the item list can be retrieved here
}

function errorCB(error, device) {
	console.log(device + " raises " + error);
}

// Define a filter to browse a video type only
var filter = new webapis.AttributeFilter('itemType', null, {'VIDEO'});
try {
	var providers = serviceProvider.getDeviceFinder().getDeviceList('MEDIAPROVIDER');
	if (providers.length > 0) {
		// search the keyword on the first DMS.
		providers[0].search(keyword, 0, 40, searchCB, errorCB, filter);
	}
} catch (e) {
	console.log(e.message);
} 
				

search() requires keyword, startIndex, requestCount, and searchFilter as input parameters. When you determine requestCount and searchFilter, you must be careful because these parameters affect search response speed. The requestCount value decreases with increased search response speed. If you do not input searchFilter when searching, all media content that is related to the keyword is returned. Meanwhile, the search efficiency goes down.

search() returns the requested number of items from the content list via MediaProviderSuccessCallback. The search results start with the index specified by the search condition. As in the example above, the item list can be retrieved in searchCB().

Retrieve Content Meta-information

After browse() or search() returns items via MediaProviderSuccessCallback, an application can get item meta-information by reading the attributes of these items.

You can get content meta-information as follows:

 
var serviceProvider; 
// it is assumed that you have obtained a serviceProvider object. 
// For further details, see the createServiceProvider() or getServiceProvider().
var keyword = "foo"; 

// Define browse callback
function searchCB(list, endOfItem, providerId) {
	// The video item list can be retrieved here
	for (var i = 0 ; i < list.length ; i ++) {
		var item = list[i];
		var uri = item.itemUri;
		var type = item.itemType;
		var title = item.title;
		var thumbnail = item.thumbnailUri;
		var duration = item.duration;
	}
}

function errorCB(error, device) {
	console.log(device + " raises " + error);
}         

// Define a filter to browse a video type only
var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"});
	
try {
	var providers = serviceProvider.getDeviceFinder().getDeviceList("MEDIAPROVIDER");
	if (providers.length > 0) {
		// Search the keyword on the first DMS.
		providers[0].search(keyword, 0, 40, searchCB, errorCB, filter);
	}
} catch(e) {
    console.log(e.message);
} 
				

The Web API provides the following information for an item.

Attribute Description Return Value
albumTitle A string value specifies the content album title. e.g. “Mr. H”
artist A string value specifies content artist. Audio artist
date This attribute’s type is Date. It specifies content date. e.g. “Fri Oct 12 2012”
duration

This attribute’s type is unsigned long long.

It specifies content total play time.

e.g. 30
extension A string value specifies content extension. e.g. “png”
fileSize This attribute’s type is double. It specifies content file size. e.g. 485376
genre A string value specifies content genre.
location This attribute’s type is SimpleCoordinates. It specifies content geolocation.
mimeType A string value specifies content MIME type. e.g. “video/mp4”
width This attribute’s type is unsigned long. It specifies content width. e.g. 225
height This attribute’s type is unsigned long. It specifies content height. e.g. 300
subtitleUri A string value specifies content subtitle URI.
thumbnailUri

A string value specifies content thumbnail URI.

The string value looks like this: http://IPAddress:Port/path.

e.g. “http://109.123.103.82:17679/FileProvider/M$0/O$1/P$JPEG_SM/I$image/jpeg/7659”
title A string value specifies content title. e.g. “testImage”
itemType This attribute’s type is ItemType. It specifies Item type. Item.ItemType enumeration
itemUri

A string value specifies item URI.

The string value looks like this: http://IPAddress:Port/path.

e.g. “http://109.123.103.82:17679/FileProvider/M$0/O$1/P$JPEG_SM/I$image/jpeg/7659”

isRootFolder This attribute’s type is Boolean. It specifies whether it is a root folder or not. e.g. true
contentBuildType This attribute’s type is ItemcontentBuildType. It specifies the content build type. Item.ItemContentBuildType enumeration