MediaProvider

Published 2014-10-28 | (Compatible with SDK 3.5 and 2012 models)

Provides the class for accessing content provider.

Method
MediaProviderType getMediaProviderType()
Get type of the media provider
Parameter None
Return Provide the type of this media provider
Exceptions  
Example  
Method
FolderItem getRootFolder()
Get root folder item
Parameter None
Return root folder item of the provider
Exceptions  
Example
var providerList = serviceapis.mediasharing.mediaproviderfinder.getMediaProviders();
var uriList = new Array();
for (var i = 0; i < providerList.length; i++) {
    var folderItem = providerList.getRootFolder();
    urList.push(folderItem.getURI());
};
Method
PendingOperation browseItems(successCallback, errorCallback, parentFolderItem, startIndex, requestCount)
Get item list in a folder by specified starting index and count
Parameter
successCallback (in MediaProviderBrowseItemsSuccessCallback)
called when the browse operation has been successfully completed
errorCallback (in MediaProviderItemsBrowseErrorCallback)
called if an error occured while browsing
parentFolderItem (in FolderItem)
folder to be retrieved
startIndex (in unsigned short )
starting zero based offset to enumerate children under the specified FolderItem
requestCount (in unsigned short)
requested number of entries under the object specified by parentFolderItem.
Return Enabling the requester to cancel this request
Exceptions ServiceAPIError with error code TYPE_MISMATCH_ERR If any of the input attributes are of the wrong type
Example
var gIdx = 0;
var gListCnt = 20;
var gEOF = false;

function onsuccess (itemlist, startidx, folderitem, eof, provider) {
    var contentList;
    gEOF = eof;

    if(!gEOF){
        gIdx = itemlist.length;
    }

    for (var i = 0; i < itemlist.length; i ++) {
        var item = itemlist[i];
        var objType = item.getType();
        var itemType = objType.type;

        switch (itemType){
            case objType.ITEM_FOLDER:
                contentList = "folder";
                break;
            case objType.ITEM_AUDIO:
                contentList = "audio";
                break;
            case objType.ITEM_VIDEO:
                contentList = "video";
                break;
            case objType.ITEM_IMAGE:
                contentList = "image";
                break;
            default:
                continue;
        }

        contentList = contentList + "|" + item.getTitle() + "\n";
    }
    alert(contentList);
};

function onerror (error, provider) {
    var errCode = error.code;
    var errMsg = "";

    switch (errcode) {
        case error.INVALID_DEVICE_ERR:
            errMsg = "The provider does not exist in the network.";
            break;
        case error.INVALID_RESPONSE_ERR:
            errMsg = "The response from the provider cannot be parsed.";
            break;
        case error.FAIL_TO_REQUEST_ERR:
            errMsg = "The request could not be sent to the provider";
            break;
    };
    alert(errMsg);
};

function showItemList (parentFolder) {
    if (!gEOF) {
        provider.browseItems(onsuccess, onerror, parentFolder, gIdx, gListCnt);
    }
};
Method
PendingOperation searchItems( successCallback, errorCallback, keyword, startIndex, requestCount)
Search items which related with specified stringt
Parameter
successCallback (in MediaProviderSearchItemsSuccessCallback)
called when the search operation has been successfully completed
errorCallback (in MediaProviderItemsSearchErrorCallback)
called if an error occured while searching
keyword (in DOMString)
requested String of result currently responded
startIndex (in unsigned short )
starting zero based offset to enumerate children under the specified FolderItem
requestCount (in unsigned short)
requested number of entries under the object specified by parentFolderItem
Return Enabling the requester to cancel this request
Exceptions ServiceAPIError with error code TYPE_MISMATCH_ERR If any of the input attributes are of the wrong type
Example
var gIdx = 0;
var gListCnt = 20;
var gEOF = false;

function onsuccess(itemlist, startidx, keyword, eof, provider) {
    var contentList;
    gEOF = eof;

    if (!gEOF) {
        gIdx = itemlist.length;
    }
    for (var i = 0; i < itemlist.length; i ++ ) {
        var item = itemlist[i];
        var objType = item.getType();
        var itemType = objType.type;

        switch (itemType) {
            case objType.ITEM_FOLDER:
                contentList = "folder";
                break;
            case objType.ITEM_AUDIO:
                contentList = "audio";
                break;
            case objType.ITEM_VIDEO:
                contentList = "video";
                break;
            case objType.ITEM_IMAGE:
                contentList = "image";
                break;
            default:
                continue;
        }
        contentList = contentList + "|" + item.getTitle() + "\n";
    }
    alert(contentList);
};

function onerror(error, provider) {
    var errCode = error.code;
    var errMsg = "";

    switch (errcode) {
        case error.INVALID_DEVICE_ERR:
            errMsg = "The provider does not exist in the network.";
            break;
        case error.INVALID_RESPONSE_ERR:
            errMsg = "The response from the provider cannot be parsed.";
            break;
        case error.FAIL_TO_REQUEST_ERR:
            errMsg = "The request could not be sent to the provider";
            break;
    };
    alert(errMsg);
};

function showItemList(keyword) {
    if (!gEOF) {
        provider.searchItems(onsuccess, onerror, keyword, gIdx, gListCnt);
    }
};