Page Example

Media Content Sample Overview

The Media Content sample application demonstrates how content information can be retrieved from the Web Device API.

The following figure illustrates the screens of the Media Content application.

Figure: Media Content screens

Media Content screens

The application opens with the screen where you can choose the type of storage to check. After choosing the storage, you can choose the type of files to be retrieved. To view the details of the file, click the file name.

Prerequisites

To ensure proper application execution, the following privileges must be set:

  • http://tizen.org/privilege/content.read
  • http://tizen.org/privilege/content.write

Source Files

You can create and view the sample application project including the source files in the IDE.

File name Description
config.xml This file contains the application information for the platform to install and launch the application, including the view mode and the icon to be used in the device menu.
index.html This is a starting file from which the application starts loading. It contains the layout of the application screens.
css/style.css This file contains the CSS styling for the application UI.
js/main.js This file contains the code for the main application module used for initialization and application methods.
js/app.js This file contains the code of main logic of the application. This module uses app.model and app.ui.
js/app.model.js This file contains the code for the access to API and data management.
js/app.ui.js This file contains the code of the view logic.
js/app.ui.template.js This file contains the code of the template module.

Implementation

To get all folders from the API, use the getDirectories() method from the tizen.content object.

getFolders: function getFolders(successCallback, errorCallback) 
{
   try 
   {
      tizen.content.getDirectories(successCallback, errorCallback);
   } 
   catch (exc) 
   {
      console.warn('getLocalMediaSource exc:' + exc.message);
   }
},

The following function requests for the content with a specific filter and sorted by the tizen.SortMode object.

getFolderItems: function getFolderItems(folderId, mediaType, folders, findItemsSuccess, findItemsError) 
{
   if (mediaType !== 'ALL') 
   {
      filter = new tizen.AttributeFilter('type', 'EXACTLY', mediaType);
   }
   try 
   {
      tizen.content.find(success, findItemsError, folder, filter, new tizen.SortMode('title', 'ASC'));
   } 
   catch (exc) 
   {
      console.warn('tizen.content.find exception: ' + exc.message);
   }
},

To set the storage change listener, use the addPropertyValueChangeListener() method from the tizen.systeminfo object.

addStorageChangeListener: function addChangeListener(changeListener)
{
   try 
   {
      tizen.systeminfo.addPropertyValueChangeListener('STORAGE', changeListener);
   } 
   catch (error) 
   {
      console.error('Add storage change listener error: ' + error.message);
   }
},

To set the content change listener, use setChangeListener() method from the tizen.content object.

addContentChangeListener: function addContentChangeListener(changeListener) 
{
   try 
   {
      tizen.content.setChangeListener(
      {
         oncontentadded: changeListener,
         oncontentremoved: changeListener
      });
   } 
   catch (error) 
   {
      console.error('Add content change listener error: ' + error.message);
   }
}