To navigate through contents structure similar to computers folders two function are defined in MediaProvider object:

getRootFolder()

return root of folder structure, type of result is FolderItem

browseItems()

it is asynchronous function, it obtain callback handlers for success and error cases

Sample

varbrowseHelper={};// helper object, what will implement browse functionalitybrowseHelper.resultItems=null;// this variable will keep finded itemsbrowseHelper.showFolderContents=function(){// this function executed when folder contents readed fullyfor(i=0;i<resultItems.length;i++){showMediaItemInfo(resultItems[i]);}}browseHelper.browseFolderInner=function(mediaProvider,folderItem){// this function doing request for all items in foldervarself=this;alert("browseHelper.browseFolder begin");// this function is callback, it called when items readedvarbrowseItemsSuccessCallback=function(sc_itemList,sc_requestedStartIndex,sc_requestedFolderItem,sc_fEndOfItems,sc_mediaProvider){alert("success callback");if(sc_itemList){alert("itemsList.length : "+sc_itemList.length);alert("requestedStartIndex : "+sc_requestedStartIndex);alert("requestedFolderItem : "+sc_requestedFolderItem.getTitle());alert("fEndOfItems : "+sc_fEndOfItems);// copy result into 'resultItems'self.resultItems=self.resultItems.concat(sc_itemList);alert("add items into resultItems, new length :"+self.resultItems.length);// all items readedself.showFolderContents();}}// this function is callback, it called when error happend during items requestvarbrowseItemsErrorCallback=function(serviceAPIError,requestedProvider){alert("serviceAPIError:"+serviceAPIError);}self.pendingOperation=null;// this variable will keep PendingOperation object, it can be used to cancel asynchronous requesttry{varstartIndex=0;// zero value means read all elements of foldervarrequestCount=0;self.pendingOperation=mediaProvider.browseItems(browseItemsSuccessCallback,browseItemsErrorCallback,folderItem,startIndex,requestCount);}catch(e){alert("browseItems exception:"+e);self.pendingOperation=null;}}// this function browse 'folderItem' of 'mediaProvider'browseHelper.browseFolder=function(mediaProvider,folderItem){self=this;self.resultItems=[];self.browseFolderInner(mediaProvider,folderItem);}// calling partvarmediaProvider=providerArray[0];// select first device from devices listvarfolderItem=mediaProvider.getRootFolder();browseHelper.browseFolder(mediaProvider,folderItem);

The “search” is searching for items using keyword parameter. Searching is doing for whole contents of media provider. Usage is similar to browseItems(), it is asynchronous request. The function use callbacks to inform about success reading or error cases.

Sample

varsearchHelper={};// helper object, what will implement search functionalitysearchHelper.resultItems=null;// this variable will keep finded itemssearchHelper.showFolderContents=function(){// this function executed when folder contents readed fullyfor(i=0;i<resultItems.length;i++){showMediaItemInfo(resultItems[i]);}}searchHelper.searchItemsInner=function(mediaProvider,keyword){// this function doing request for itemsvarself=this;alert("searchHelper.searchItemsInner begin");// this function is callback, it called when next portion of items readedvarsearchItemsSuccessCallback=function(sc_itemList,sc_requestedStartIndex,sc_keyword,sc_fEndOfItems,sc_mediaProvider){alert("success callback");if(sc_itemList){alert("itemsList.length : "+sc_itemList.length);alert("requestedStartIndex : "+sc_requestedStartIndex);alert("keyword : "+sc_keyword);alert("fEndOfItems : "+sc_fEndOfItems);// copy result into 'resultItems' and request for another portion if neededself.resultItems=self.resultItems.concat(sc_itemList);alert("add items into resultItems, new length :"+self.resultItems.length);// all items readedself.showFolderContents();}}// this function is callback, it called when error happend during items requestvarsearchItemsErrorCallback=function(serviceAPIError,requestedProvider){alert("serviceAPIError:"+serviceAPIError);}self.pendingOperation=null;// this variable will keep PendingOperation object, it can be used to cancel asynchronous requesttry{varstartIndex=0;// zero value means read all elements of resultvarrequestCount=0;self.pendingOperation=mediaProvider.searchItems(searchItemsSuccessCallback,searchItemsErrorCallback,keyword,startIndex,requestCount);}catch(e){alert("searchItems exception: "+e);self.pendingOperation=null;}}// this function search items by "keyword" in "mediaProvider"searchHelper.search=function(mediaProvider,keyword){self=this;self.resultItems=[];self.searchItemsInner(mediaProvider,keyword);}// calling partvarmediaProvider=providerArray[0];// select first device from devices listsearchHelper.searchFolder(mediaProvider,"Jackson");