ASFService API

To use Samsung Product API,

<script type="text/javascript" src="$WEBAPIS/webapis/webapis.js"></script>

Should be loaded in index.html

This API enables initiating the AllShare Framework.

Since : 2.3

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Summary of Interfaces and Methods

Interface

Method

Item

WebApiAllShareObject

AllshareManager

DOMString getVersion();

ServiceConnectorObject

ServiceProviderCreateSuccessCallback

void onsuccess(ServiceProvider serviceProvider);

ServiceProviderErrorCallback

void onerror(WebAPIError error, ServiceState state);

ServiceConnector

void createServiceProvider(optional ServiceProviderCreateSuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
void deleteServiceProvider(optional SuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
ServiceProvider getServiceProvider();

ServiceProvider

DeviceFinder getDeviceFinder();
ServiceState getServiceState();

DeviceDiscoveryCallback

void ondeviceadded(Device device);
void ondeviceremoved(Device device);

Icon

DeviceFinder

Device getDevice(DeviceType deviceType, DeviceId id);
Device[] getDeviceList(DeviceType deviceType);
void refresh();
long addDeviceDiscoveryListener(DeviceDiscoveryCallback deviceDiscoveryCallback);
void removeDeviceDiscoveryListener(long deviceDiscoveryListener);
Object getProperty(string propertyName, Device deviceInfo)

Device

MediaProviderSuccessCallback

void onsuccess(Item[] itemList, boolean endOfItems, DeviceId providerId);

MediaProviderErrorCallback

void onerror(WebAPIError error, DeviceId providerId);

MediaProvider

void browse(Item folderItem, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback browseCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? browseFilter, optional SortMode? sortMode);
void search(DOMString keyword, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback successCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? searchFilter);

1. Type Definitions

1.1 ItemType

Specifies the item type.

enum ItemType {
  "AUDIO",
  "FOLDER",
  "IMAGE",
  "UNKNOWN",
  "VIDEO"
};

The following values are supported

  • AUDIO : Audio type
  • FOLDER : Folder type
  • IMAGE : Image type
  • UNKNOWN : Unknown media type
  • VIDEO : Video type

1.2 ServiceState

Specifies the ASF service state.

enum ServiceState {
  "DISABLED",
  "ENABLED",
  "UNKNOWN"
};

The following values are supported

  • DISABLED : Disabled
  • ENABLED : Enabled
  • UNKNOWN : Unknown

1.3 DeviceType

Specifies the device types which can be discovered.

enum DeviceType {
  "MEDIAPROVIDER",
  "UNKNOWN"
};

The following values are supported

  • MEDIAPROVIDER : Media provider
  • UNKNOWN : Unknown device type

1.4 DeviceDomain

Specifies the network domain in which the device is located.

enum DeviceDomain {
  "LOCAL_NETWORK",
  "UNKNOWN"
};

The following values are supported

  • LOCAL_NETWORK : Located in a local network area
  • UNKNOWN : Located in an unknown area

1.5 DeviceId

Device identifier

typedef DOMString DeviceId;

2. Interfaces

2.1 Item

Constructs an object that represents a media item or folder.

[Constructor(DOMString uri, optional DOMString mimeType, optional DOMString title)] interface Item {
  readonly attribute DOMString albumTitle;
  readonly attribute DOMString artist;
  readonly attribute Date date;
  readonly attribute unsigned long long duration;
  readonly attribute DOMString extension;
  readonly attribute double fileSize;
  readonly attribute DOMString genre;
  readonly attribute DOMString mimeType;
  readonly attribute unsigned long? width;
  readonly attribute unsigned long? height;
  attribute DOMString? subtitleUri;
  readonly attribute DOMString? thumbnailUri;
  attribute DOMString title;
  readonly attribute ItemType itemType;
  readonly attribute DOMString itemUri;
  readonly attribute boolean isRootFolder;
  readonly attribute ItemContentBuildType contentBuildType;
};

Constructor

Item(DOMString uri, optional DOMString mimeType, optional DOMString title)

Parameters :

  • uri : Item path
  • mimeType [optional][nullable] : Item MIME type
  • title [optional][nullable] : Item title

Attributes

  • readonly DOMString albumTitle
    Album title of the content
  • readonly DOMString artist
    Artist name of the content
  • readonly Date date
    Content creation date
  • readonly unsigned long long duration
    Duration or content total play time
  • readonly DOMString extension
    File extension of the content
  • readonly double fileSize
    File size of the content
  • readonly DOMString genre
    Genre of the content
  • readonly DOMString mimeType
    MIME type of the content
  • readonly unsigned long width [nullable]
    Width of the content
  • readonly unsigned long height [nullable]
    Height of the content
  • DOMString subtitleUri [nullable]
    Subtitle URI of the content
  • readonly DOMString thumbnailUri [nullable]
    Thumbnail image URI
  • DOMString title
    Title of the content
  • readonly ItemType itemType
    Item type of the content
  • readonly DOMString itemUri
    Item URI of the content
  • readonly boolean isRootFolder
    Whether the item is a root folder
  • readonly ItemContentBuildType contentBuildType
    Build type of the content

2.2 WebApiAllShareObject

Defines an AllShare object instance.

[NoInterfaceObject] interface WebApiAllShareObject {
  readonly attribute AllShare allshare;
};
WebApi implements WebApiAllShareObject;

Attributes

  • readonly AllShare allshare
    Provides interfaces for acquiring AllShare devices and connecting to them.

2.3 AllshareManager

AllShare root API

[NoInterfaceObject] interface AllshareManager {
  DOMString getVersion();
};

Methods

getVersion

Retrieves the allshare plugin version number.

DOMString getVersion();

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Return Value :

  • DOMString : Plugin version

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method

Code Example :

try {
  var value = webapis.allshare.getVersion();
  console.log("version value = " + value);
}
catch (error) {
  console.log("error code = " + error.code);
}

2.4 ServiceConnectorObject

Defines a WebApi object instance.

[NoInterfaceObject] interface ServiceConnectorObject {
  attribute ServiceConnector serviceconnector;
};
AllShare implements ServiceConnectorObject;

Attributes

  • ServiceConnector serviceconnector
    Provides interfaces for connecting to the ASF service.

2.5 ServiceProviderCreateSuccessCallback

Defines the callback invoked when a ServiceProvider object is created successfully.

[Callback=FunctionOnly, NoInterfaceObject] interface ServiceProviderCreateSuccessCallback {
  void onsuccess(ServiceProvider serviceProvider);
};

Methods

onsuccess

Callback method invoked when a ServiceProvider object is successfully created.

void onsuccess(ServiceProvider serviceProvider);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • serviceProvider : Created ServiceProvider object

Code Example :

// onsuccess sProviderCallback
function sProviderCallback(provider) {
  
  console.log("The service provider was obtained");
}

// Define the ServiceProvider creation error callback
function eProviderCallback(error, state) {
  
  console.log(error.name);
  console.log("Current ASF service state: " + state);
  
}

// Try to create the ServiceProvider object
try {
  webapis.allshare.serviceconnector.createServiceProvider(sProviderCallback, eProviderCallback);
}
catch(e) {
  console.log(e.message);
}

2.6 ServiceProviderErrorCallback

Defines the callback invoked if a ServiceProvider object operation fails.

[Callback=FunctionOnly, NoInterfaceObject] interface ServiceProviderErrorCallback {
  void onerror(WebAPIError error, ServiceState state);
};

Methods

onerror

Callback method invoked if a ServiceProvider operation fails.

void onerror(WebAPIError error, ServiceState state);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • error : Object indicating the error type and message
  • state : Current service state

Exceptions :

  • WebAPIException
    • with error type UnknownError, for any other error.

Code Example :

// onerror eProviderCallback
function sProviderCallback(provider) {
  
  console.log("The service provider was obtained");
}

// Define the ServiceProvider creation error callback
function eProviderCallback(error, state) {
  
  console.log(error.name);
  console.log("Current ASF service state: " + state);
  
}

// Try to create the ServiceProvider object
try {
  webapis.allshare.serviceconnector.createServiceProvider(sProviderCallback, eProviderCallback);
}
catch(e) {
  console.log(e.message);
}

2.7 ServiceConnector

Provides the connection to the AllShare Framework(ASF) service.

[NoInterfaceObject] interface ServiceConnector {
  void createServiceProvider(optional ServiceProviderCreateSuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
  void deleteServiceProvider(optional SuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
  ServiceProvider getServiceProvider();
};

Methods

createServiceProvider

Creates a ServiceProvider object.

void createServiceProvider(optional ServiceProviderCreateSuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • successCallback [optional][nullable] : Callback method to invoke if the request is successful
  • errorCallback [optional][nullable] : Callback method to invoke if the request fails

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Since : 2.3

Code Example :

// Define the ServiceProvider creation success callback
function sProviderCallback(provider) {
  
  console.log("The service provider was obtained");
}

// Define the ServiceProvider creation error callback
function eProviderCallback(error, state) {
  
  console.log(error.name);
  console.log("Current ASF service state: " + state);
  
}

// Try to create the ServiceProvider object
try {
  webapis.allshare.serviceconnector.createServiceProvider(sProviderCallback, eProviderCallback);
}
catch(e) {
  console.log(e.message);
}

deleteServiceProvider

Deletes a ServiceProvider object.

void deleteServiceProvider(optional SuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • successCallback [optional][nullable] : Callback method to invoke if the request is successful
  • errorCallback [optional][nullable] : Callback method to invoke if the request fails

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method.

Since : 2.3

Code Example :

// You must already have a ServiceProvider object
var serviceProvider;

// Define the ServiceProvider deletion success callback
function sProviderDeleteCallback() {
  
  console.log("The ASF service provider has been deleted properly.");
}

// Define the ServiceProvider deletion error callback
function eProviderDeleteCallback(error, state) {
  
  console.log(error.name);
  console.log("The current ASF service state: " + state);
  
}

// Try to delete the ServiceProvider object
try {
  webapis.allshare.serviceconnector.deleteServiceProvider(sProviderDeleteCallback, eProviderDeleteCallback);
}
catch(e) {
  console.log(e.message);
}

getServiceProvider

Returns a ServiceProvider object that is connected to the AllShare Framework.

ServiceProvider getServiceProvider();

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Return Value :

  • ServiceProvider : ServiceProvider ServiceProvider object connected to the AllShare Framework

Exceptions :

  • WebAPIException
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

try {
  // You must already have a ServiceProvider object
  var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
  if (serviceProvider == null) {
    console.log("Service provider was not created properly");
  }
}
catch(e) {
  console.log(e.message);
}

2.8 ServiceProvider

Provides methods for obtaining a DeviceFinder object.

[NoInterfaceObject] interface ServiceProvider {
  DeviceFinder getDeviceFinder();
  ServiceState getServiceState();
};

Methods

getDeviceFinder

Returns the DeviceFinder object used to find AllShare devices.

DeviceFinder getDeviceFinder();

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Return Value :

Exceptions :

  • WebAPIException
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider  = webapis.allshare.serviceconnector.getServiceProvider();

try {
  deviceFinder = serviceProvider.getDeviceFinder();
} catch(e) {
  console.log(e.name);
}

getServiceState

Retrieves the current ASF service state.

ServiceState getServiceState();

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Return Value :

Exceptions :

  • WebAPIException
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

// You must already have a ServiceProvider object
var serviceProvider;

try {
  serviceState = serviceProvider.getServiceState();
} catch(e) {
  console.log(e.name);
}

2.9 DeviceDiscoveryCallback

Defines a generic callback for device discovery event notifications.

[Callback, NoInterfaceObject] interface DeviceDiscoveryCallback {
  void ondeviceadded(Device device);
  void ondeviceremoved(Device device);
};

Methods

ondeviceadded

Callback method invoked when a new device appears on the network.

void ondeviceadded(Device device);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • device : Newly-discovered device

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();

var monitoringCB = {
  ondeviceadded : function (device) { console.log("new device has appeared :" + device.name); },
  ondeviceremoved : function (device) { console.log("a device has disappeared :" + device.name); }
}

try {
  var listenerId = serviceProvider.getDeviceFinder().addDeviceDiscoveryListener(monitoringCB);
  
} catch(e) {
  console.log(e.name);
}

ondeviceremoved

Callback method invoked when a device disappears from the network.

void ondeviceremoved(Device device);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • device : Device that has disappeared

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();

var monitoringCB = {
  ondeviceadded : function (device) { console.log("new device has appeared :" + device.name); },
  ondeviceremoved : function (device) { console.log("a device has disappeared :" + device.name); }
}

try {
  var listenerId = serviceProvider.getDeviceFinder().addDeviceDiscoveryListener(monitoringCB);
  
} catch(e) {
  console.log(e.name);
}

2.10 Icon

Defines icon information.

[NoInterfaceObject] interface Icon {
  readonly attribute long depth;
  readonly attribute long height;
  readonly attribute long width;
  readonly attribute DOMString mimeType;
  readonly attribute DOMString iconUri;
};

Attributes

  • readonly long depth
    Icon color depth, in bits per pixel
  • readonly long height
    Icon height
  • readonly long width
    Icon width
  • readonly DOMString mimeType
    Icon MIME type
  • readonly DOMString iconUri
    Icon URI

2.11 DeviceFinder

Provides methods for finding AllShare devices.

[NoInterfaceObject] interface DeviceFinder {
  Device getDevice(DeviceType deviceType, DeviceId id);
  Device[] getDeviceList(DeviceType deviceType);
  void refresh();
  long addDeviceDiscoveryListener(DeviceDiscoveryCallback deviceDiscoveryCallback);
  void removeDeviceDiscoveryListener(long deviceDiscoveryListener);
  Object getProperty(string propertyName, Device deviceInfo);
};

Methods

getDevice

Returns a Device object with a specific device ID and type.

Device getDevice(DeviceType deviceType, DeviceId id);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • deviceType : Device type i.e. MEDIAPROVIDER
  • id : The unique ID of the device

Return Value :

  • Device : Device Device object

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var mediaProviderId;  // The MEDIAPROVIDER's device ID is assumed to be known

try {
  var deviceFinder = serviceProvider.getDeviceFinder();
  // Get the MediaProvider device object
  var device = deviceFinder.getDevice("MEDIAPROVIDER", mediaProviderId);
  
  // Print the device ID
  console.log(device.id);
  
} catch(e) {
  console.log(e.name);
}

getDeviceList

Lists the discovered devices with a specific device type.

Device[] getDeviceList(DeviceType deviceType);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • deviceType : Device type i.e. MEDIAPROVIDER

Return Value :

  • Device[] : Device[] Device array

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider().

try {
  var deviceFinder = serviceProvider.getDeviceFinder();
  var devices = deviceFinder.getDeviceList("MEDIAPROVIDER");
  
  // Print the number of available MediaProvider devices
  console.log(devices.length);
  
} catch(e) {
  console.log(e.name);
}

refresh

Refreshes the list of devices on the network.

void refresh();

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method
    • with error type UnknownError, for any other error.

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();

try {
  var deviceFinder = serviceProvider.getDeviceFinder();
  
  var providers = deviceFinder.getDeviceList("MEDIAPROVIDER");
  if (providers.length == 0) {
    // Refresh the device list and retrieve the provider list again
    deviceFinder.refresh();
    providers = deviceFinder.getDeviceList("MEDIAPROVIDER");
  }
} catch(e) {
  console.log(e.name);
}

addDeviceDiscoveryListener

Registers a device discovery event listener.

long addDeviceDiscoveryListener(DeviceDiscoveryCallback deviceDiscoveryCallback);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • deviceDiscoveryCallback : Callback method invoked when a device discovery event occurs.

Return Value :

  • long : long Event listener ID

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();

var monitoringCB = {
  ondeviceadded : function (device) { console.log("new device has appeared :" + device.name); },
  ondeviceremoved : function (device) { console.log("a device has disappeared :" + device.name); }
}

try {
  var listenerId = serviceProvider.getDeviceFinder().addDeviceDiscoveryListener(monitoringCB);
  
} catch(e) {
  console.log(e.name);
}

removeDeviceDiscoveryListener

Unregisters a device discovery event listener.

void removeDeviceDiscoveryListener(long deviceDiscoveryListener);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • deviceDiscoveryListener : Event listener ID

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var listenerId; // Listener ID returned from addDeviceDiscoveryListener
var monitoringCB = {
  ondeviceadded : function (device) { console.log("new device has appeared :" + device.name); },
  ondeviceremoved : function (device) { console.log("a device has disappeared :" + device.name); }
}

try {
  var listenerId = serviceProvider.getDeviceFinder().addDeviceDiscoveryListener(monitoringCB);
  serviceProvider.getDeviceFinder().removeDeviceDiscoveryListener(listenerId);
} catch(e) {
  console.log(e.name);
}

getProperty

get Properties of a Device

Object getProperty(string propertyName, Device deviceInfo);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • propertyName : string
  • deviceInfo : DeviceObject

Return Value :

  • Object : Object

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type SecurityError, if the application does not have the privilege to call this method
    • with error type UnknownError, for any other error.

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var mediaProviderId;  // The MEDIAPROVIDER's device ID is assumed to be known
var propertyName; // The MEDIAPROVIDER's propertyname  is assumed to be known
try {
  var deviceFinder = serviceProvider.getDeviceFinder();
  // Get the MediaProvider device object
  var device = deviceFinder.getDevice("MEDIAPROVIDER", mediaProviderId);
  var propertyData = deviceFinder.getProperty(propertyName , device);
  console.log(propertyData)
  
} catch(e) {
  console.log(e.name);
}

2.12 Device

Retrieves information about a device.

[NoInterfaceObject] interface Device {
  readonly attribute DeviceId id;
  readonly attribute DeviceDomain deviceDomain;
  readonly attribute DeviceType deviceType;
  readonly attribute DOMString ipAddress;
  readonly attribute DOMString? modelName;
  readonly attribute DOMString name;
  readonly attribute DOMString nic;
};

Attributes

  • readonly DeviceId id
    Unique device ID
  • readonly DeviceDomain deviceDomain
    Device domain
  • readonly DeviceType deviceType
    Device type
  • readonly DOMString ipAddress
    Device IPv4 address
  • readonly DOMString modelName [nullable]
    Device model name
  • readonly DOMString name
    Device name
  • readonly DOMString nic
    Device NIC (Network Interface Controller) name

2.13 MediaProviderSuccessCallback

Defines the callback invoked when a provider object completes a retrieval operation successfully.

[Callback=FunctionOnly, NoInterfaceObject] interface MediaProviderSuccessCallback {
  void onsuccess(Item[] itemList, boolean endOfItems, DeviceId providerId);
};

Methods

onsuccess

Callback method for a successful retrieval request.

void onsuccess(Item[] itemList, boolean endOfItems, DeviceId providerId);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • itemList : Item list. If there are no items, an empty list is returned.
  • endOfItems : End of items flag
  • providerId : Provider device identifier

Code Example :

//onsuccess searchCB
var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var keyword = "foo";

// Define a browse callback
function searchCB(list, endOfItem, providerId){
  // Retrieve the item list
}

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

// Define a filter to browse videos only
var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"});

try {
  var providers = serviceProvider.getDeviceFinder().getDeviceList("MEDIAPROVIDER");
  if (providers.length > 0) {
    // Search for the keyword in the first DMS
    providers[0].search(keyword, 0, 40, searchCB, errorCB, filter);
  }
} catch(e) {
  console.log(e.message);
}

2.14 MediaProviderErrorCallback

Defines a generic error callback for provider-related operations.

[Callback=FunctionOnly, NoInterfaceObject] interface MediaProviderErrorCallback {
  void onerror(WebAPIError error, DeviceId providerId);
};

Methods

onerror

Callback method invoked if an error occurs.

void onerror(WebAPIError error, DeviceId providerId);

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • error : Object indicating the error type and message
  • providerId : Provider device identifier

Exceptions :

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method

Code Example :

//onerror errorCB
var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var keyword = "foo";

// Define a browse callback
function searchCB(list, endOfItem, providerId){
  // Retrieve the item list
}

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

// Define a filter to browse videos only
var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"});

try {
  var providers = serviceProvider.getDeviceFinder().getDeviceList("MEDIAPROVIDER");
  if (providers.length > 0) {
    // Search for the keyword in the first DMS
    providers[0].search(keyword, 0, 40, searchCB, errorCB, filter);
  }
} catch(e) {
  console.log(e.message);
}

2.15 MediaProvider

Enables sharing media content between devices.

[NoInterfaceObject] interface MediaProvider {
  readonly attribute boolean isSearchable;
  readonly attribute Item rootFolder;

  void browse(Item folderItem, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback browseCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? browseFilter, optional SortMode? sortMode);
  void search(DOMString keyword, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback successCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? searchFilter);
};

Attributes

  • readonly boolean isSearchable
    Whether the provider supports the search capability
  • readonly Item rootFolder
    Root folder object

Methods

browse

Gets the item list in a folder at the specified starting index and count.

void browse(Item folderItem, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback browseCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? browseFilter, optional SortMode? sortMode);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • folderItem : Folder
  • startIndex : Starting zero-based offset
  • requestCount : Requested number of entries
  • browseCallback : Callback invoked when the browse operation is successful. It returns a set of items matching the filter.
  • errorCallback [optional][nullable] : Generic error callback for provider-related operations
  • browseFilter [optional][nullable] : Browse filter to be applied. Parameters can include AttributeFilter objects constructed with ("itemType", null , ItemType[]).
  • sortMode [optional][nullable] : Sorting to use on the content list. Sorting by title, date, artist, or albumTitle attribute is only supported on the Tizen Web platform. Other Web platforms ignore this parameter.

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider  = webapis.allshare.serviceconnector.getServiceProvider();

// Define a browse callback
function browseCB(list, endOfItem, providerId) {
  // Retrieve the item list
}

function errorCB(error, deviceId) {
  console.log(error.message);
}

// Define a filter to browse videos 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 the first DMS from the root folder
    providers[0].browse(providers[0].rootFolder, 0, 10, browseCB, errorCB, filter, mode);
  }
} catch(e) {
  console.log(e.message);
}

search

Searches content for a specific keyword.

void search(DOMString keyword, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback successCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? searchFilter);

Product : TV, AV, B2B

Privilege Level : Public

Privilege : http://developer.samsung.com/privilege/allshare

Parameters :

  • keyword : Search keyword
  • startIndex : Starting zero-based offset
  • requestCount : Requested number of entries
  • successCallback : Callback to invoke when the search operation is successful. It returns a set of items matching the filter.
  • errorCallback [optional][nullable] : Generic error callback for provider-related operations
  • searchFilter [optional][nullable] : Filter applied to the search result. Parameters can include AttributeFilter objects constructed with ("itemType", null , ItemType[]).

Exceptions :

  • WebAPIException
    • with error type TypeMismatchError, if an input parameter is not compatible with its expected type.
    • with error type UnknownError, for any other error.
    • with error type SecurityError, if the application does not have the privilege to call this method

Since : 2.3

Code Example :

var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider();
var keyword = "foo";

// Define a browse callback
function searchCB(list, endOfItem, providerId){
  // Retrieve the item list
}

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

// Define a filter to browse videos only
var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"});

try {
  var providers = serviceProvider.getDeviceFinder().getDeviceList("MEDIAPROVIDER");
  if (providers.length > 0) {
    // Search for the keyword in the first DMS
    providers[0].search(keyword, 0, 40, searchCB, errorCB, filter);
  }
} catch(e) {
  console.log(e.message);
}

3. Full WebIDL

module ASFService {
  enum ItemType {
    "AUDIO",
    "FOLDER",
    "IMAGE",
    "UNKNOWN",
    "VIDEO"
  };

  enum ServiceState {
    "DISABLED",
    "ENABLED",
    "UNKNOWN"
  };

  enum DeviceType {
    "MEDIAPROVIDER",
    "UNKNOWN"
  };

  enum DeviceDomain {
    "LOCAL_NETWORK",
    "UNKNOWN"
  };

  typedef DOMString DeviceId;

  [Constructor(DOMString uri, optional DOMString mimeType, optional DOMString title)] interface Item {
    readonly attribute DOMString albumTitle;
    readonly attribute DOMString artist;
    readonly attribute Date date;
    readonly attribute unsigned long long duration;
    readonly attribute DOMString extension;
    readonly attribute double fileSize;
    readonly attribute DOMString genre;
    readonly attribute DOMString mimeType;
    readonly attribute unsigned long? width;
    readonly attribute unsigned long? height;
    attribute DOMString? subtitleUri;
    readonly attribute DOMString? thumbnailUri;
    attribute DOMString title;
    readonly attribute ItemType itemType;
    readonly attribute DOMString itemUri;
    readonly attribute boolean isRootFolder;
    readonly attribute ItemContentBuildType contentBuildType;
  };

  [NoInterfaceObject] interface WebApiAllShareObject {
    readonly attribute AllShare allshare;
  };

  WebApi implements WebApiAllShareObject;

  [NoInterfaceObject] interface AllshareManager {
    DOMString getVersion();
  };

  [NoInterfaceObject] interface ServiceConnectorObject {
    attribute ServiceConnector serviceconnector;
  };

  AllShare implements ServiceConnectorObject;

  [Callback=FunctionOnly, NoInterfaceObject] interface ServiceProviderCreateSuccessCallback {
    void onsuccess(ServiceProvider serviceProvider);
  };

  [Callback=FunctionOnly, NoInterfaceObject] interface ServiceProviderErrorCallback {
    void onerror(WebAPIError error, ServiceState state);
  };

  [NoInterfaceObject] interface ServiceConnector {
    void createServiceProvider(optional ServiceProviderCreateSuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
    void deleteServiceProvider(optional SuccessCallback? successCallback, optional ServiceProviderErrorCallback? errorCallback);
    ServiceProvider getServiceProvider();
  };

  [NoInterfaceObject] interface ServiceProvider {
    DeviceFinder getDeviceFinder();
    ServiceState getServiceState();
  };

  [Callback, NoInterfaceObject] interface DeviceDiscoveryCallback {
    void ondeviceadded(Device device);
    void ondeviceremoved(Device device);
  };

  [NoInterfaceObject] interface Icon {
    readonly attribute long depth;
    readonly attribute long height;
    readonly attribute long width;
    readonly attribute DOMString mimeType;
    readonly attribute DOMString iconUri;
  };

  [NoInterfaceObject] interface DeviceFinder {
    Device getDevice(DeviceType deviceType, DeviceId id);
    Device[] getDeviceList(DeviceType deviceType);
    void refresh();
    long addDeviceDiscoveryListener(DeviceDiscoveryCallback deviceDiscoveryCallback);
    void removeDeviceDiscoveryListener(long deviceDiscoveryListener);
    Object getProperty(string propertyName, Device deviceInfo);
  };

  [NoInterfaceObject] interface Device {
    readonly attribute DeviceId id;
    readonly attribute DeviceDomain deviceDomain;
    readonly attribute DeviceType deviceType;
    readonly attribute DOMString ipAddress;
    readonly attribute DOMString? modelName;
    readonly attribute DOMString name;
    readonly attribute DOMString nic;
  };

  [Callback=FunctionOnly, NoInterfaceObject] interface MediaProviderSuccessCallback {
    void onsuccess(Item[] itemList, boolean endOfItems, DeviceId providerId);
  };

  [Callback=FunctionOnly, NoInterfaceObject] interface MediaProviderErrorCallback {
    void onerror(WebAPIError error, DeviceId providerId);
  };

  [NoInterfaceObject] interface MediaProvider {
    readonly attribute boolean isSearchable;
    readonly attribute Item rootFolder;
  
    void browse(Item folderItem, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback browseCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? browseFilter, optional SortMode? sortMode);
    void search(DOMString keyword, unsigned long startIndex, unsigned long requestCount, MediaProviderSuccessCallback successCallback, optional MediaProviderErrorCallback? errorCallback, optional AbstractFilter? searchFilter);
  };

};