The Content API provides functionality to discover content such as images, videos, music, or others.
It is possible to search for specific content using filters. The API also supports setting the attributes of specific content.
For more information on the Content features, see Stored Content Management Guide.
Playlist functionality has been added in Tizen 2.3.
Since 2.0
enum ContentDirectoryStorageType { "INTERNAL", "EXTERNAL" }:
Defines whether a content directory is stored on internal or external storage (such as a removable memory card).
enum ContentType { "IMAGE", "VIDEO", "AUDIO", "OTHER" };
Defines the type of content such as an image, video, audio, or any other.
Remark: "OTHER" type is added since Tizen 2.1 and since 4.0 it is optional type, related to http://tizen.org/feature/content.scanning.others feature. One can check "OTHER" type support using systeminfo API with tizen.systeminfo.getCapability("http://tizen.org/feature/content.scanning.others").
enum AudioContentLyricsType { "SYNCHRONIZED", "UNSYNCHRONIZED" };
Defines whether the lyrics supplied with an audio file is time-synchronized.
enum ImageContentOrientation { "NORMAL", "FLIP_HORIZONTAL", "ROTATE_180", "FLIP_VERTICAL", "TRANSPOSE", "ROTATE_90", "TRANSVERSE", "ROTATE_270" };
Defines the orientation of an image.
Content identifier.
typedef DOMString ContentId;
Content directory identifier.
typedef DOMString ContentDirectoryId;
Playlist identifier.
typedef DOMString PlaylistId;
Since 2.3
Defines what is instantiated by the Tizen object.
[NoInterfaceObject] interface ContentManagerObject { readonly attribute ContentManager content; };
Tizen implements ContentManagerObject;
The tizen.content object allows accessing the functionality of the Content module.
The ContentManager interface provides operations to retrieve and manipulate content.
[NoInterfaceObject] interface ContentManager { void update(Content content) raises(WebAPIException); void updateBatch(Content[] contents, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void getDirectories(ContentDirectoryArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void find(ContentArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional ContentDirectoryId? directoryId, optional AbstractFilter? filter, optional SortMode? sortMode, optional unsigned long? count, optional unsigned long? offset) raises(WebAPIException); void scanFile(DOMString contentURI, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void scanDirectory(DOMString contentDirURI, boolean recursive, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void cancelScanDirectory(DOMString contentDirURI) raises(WebAPIException); long addChangeListener(ContentChangeCallback changeCallback) raises(WebAPIException); void removeChangeListener(long listenerId) raises(WebAPIException); void getPlaylists(PlaylistArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void createPlaylist(DOMString name, PlaylistSuccessCallback successCallback, optional ErrorCallback? errorCallback, optional Playlist? sourcePlaylist) raises(WebAPIException); void removePlaylist(PlaylistId id, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void createThumbnail(Content content, ThumbnailSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
update
Updates attributes of content in the content database synchronously.
void update(Content content);
When an application has changed some attributes of the content, this method allows writing it back to the content database.
Privilege level: public
Privilege: http://tizen.org/privilege/content.write
Remark : The editableAttributes in the Content interface indicates the attributes that can be changed. This API does not support updating the metadata of a file.
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
with error type SecurityError, if the application does not have the privilege to call this method.
with error type UnknownError, in any other error case.
Code example:
// Assume the content is a Content object as a result of find method. // Check the description is editable, and then set a description. if (content.editableAttributes.indexOf("description") >= 0) { content.description = "Sample content"; } tizen.content.update(content);
updateBatch
Updates a batch of content attributes in the content database asynchronously.
void updateBatch(Content[] contents, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
When an application has changed any attributes in the array of content, this method allows writing them back to the content database.
The errorCallback is launched with these error types:
with error type TypeMismatchError, if the input parameter is not compatible with the expected type for that parameter.
// The following example increases rating of an content by 1 function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function successCB() { console.log('Attributes set successfully'); } // Assume the content is a Content object as a result of find method. // Check the rating is editable, and then increase by 1. if (content.editableAttributes.indexOf("rating") >= 0) { content.rating++; } tizen.content.updateBatch([content], successCB, errorCB);
getDirectories
Gets a list of content directories.
getDirectories(ContentDirectoryArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);
This method returns (via callback) a list of content directory objects. To obtain a list of contents in a specific directory, use the find() method with the directory ID.
The errorCallback is launched with this error type:
// The following example retrieves content directories in the storage. function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function printDirectory(directory, index, directories) { console.log('directoryURI: ' + directory.directoryURI + ' Title: ' + directory.title); } function getDirectoriesCB(directories) { directories.forEach(printDirectory); } tizen.content.getDirectories(getDirectoriesCB, errorCB);
find
Finds contents that satisfy the conditions set by a filter.
find(ContentArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional ContentDirectoryId? directoryId, optional AbstractFilter? filter, optional SortMode? sortMode, optional unsigned long? count, optional unsigned long? offset);
This method allows searching based on a supplied filter. For more details on AbstractFilter, see the Tizen module. The filter allows precise searching such as "return all songs by artist U2, ordered by name".
Privilege: http://tizen.org/privilege/content.read
// The following example retrieves all songs from the album "The Joshua Tree", by artist "U2", ordered by the name. var count = 100; var offset = 0; var sortMode = new tizen.SortMode("name", "ASC"); var artistFilter = new tizen.AttributeFilter("artists", "EXACTLY", "U2"); var albumFilter = new tizen.AttributeFilter("album", "EXACTLY", "The Joshua Tree"); var filter = new tizen.CompositeFilter("INTERSECTION", [albumFilter, artistFilter]); function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function printContent(content, index, contents) { console.log('Name: ' + content.name + ' Title: ' + content.title + 'URL: ' + content.contentURI + 'MIME: ' + content.mimeType); } function findCB(contents) { console.log('The Joshua Tree by U2:'); contents.forEach(printContent); // Increase the offset as much as the count and then find content again. if (contents.length === count) { offset += count; tizen.content.find(findCB, errorCB, null, filter, sortMode, count, offset); } } tizen.content.find(findCB, errorCB, null, filter, sortMode, count, offset);
scanFile
Scans a file to create or update content in the content database.
void scanFile(DOMString contentURI, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Since 2.1
When an application creates or updates content, this method allows to scan it and then insert or update the content in the content database.
with error type InvalidValuesError, if any of the input parameters contain an invalid value (e.g. given contentURI is an empty string).
// The following example scan 'tizen.jpg' in media directory function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function successCB(path) { console.log('scanning is completed'); } tizen.filesystem.resolve("images/tizen.jpg", function(imageFile) { tizen.content.scanFile(imageFile.toURI(), successCB, errorCB); });
scanDirectory
Scans a content directory to create or update content in the content database.
void scanDirectory(DOMString contentDirURI, boolean recursive, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Since: 2.4
When an application creates or updates content in a directory, this method allows to scan it and then insert or update the content in the content database. If a directory must not be scanned, the file .scan_ignore has to be created in it.
with error type InvalidValuesError, if any of the input parameters contain an invalid value (e.g. given contentDirURI is an empty string).
with error type UnknownError, if any other error occurs.
// The following example scans 'images' directory function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function successCB(path) { console.log('scanning is completed'); } tizen.filesystem.resolve("images", function(directory) { tizen.content.scanDirectory(directory.toURI(), true, successCB, errorCB); });
cancelScanDirectory
Cancels a scan process of a content directory.
void cancelScanDirectory(DOMString contentDirURI);
When a scan of a given directory is running it may be canceled by this function.
tizen.content.cancelScanDirectory(directory.toURI());
addChangeListener
Adds a listener which receives notifications when content changes.
long addChangeListener(ContentChangeCallback changeCallback);
Since: 3.0
Return value:
long Identifier of the newly added listener.
with error type AbortError, if the operation cannot be finished properly.
var listener = { oncontentadded: function(content) { console.log(content.contentURI + ' content is added'); }, oncontentupdated: function(content) { console.log(content.contentURI + ' content is updated'); }, oncontentremoved: function(id) { console.log(id + ' is removed'); }, oncontentdiradded: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is added'); }, oncontentdirupdated: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is updated'); }, oncontentdirremoved: function(id) { console.log(id + ' directory is removed'); } }; // Adds the listener var listenerId = tizen.content.addChangeListener(listener); console.log('Listener ID: ' + listenerId);
Output example:
Listener ID: 1
removeChangeListener
Removes a listener which receives notifications about content changes.
void removeChangeListener(long listenerId);
var listener = { oncontentadded: function(content) { console.log(content.contentURI + ' content is added'); }, oncontentupdated: function(content) { console.log(content.contentURI + ' content is updated'); }, oncontentremoved: function(id) { console.log(id + ' is removed'); }, oncontentdiradded: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is added'); }, oncontentdirupdated: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is updated'); }, oncontentdirremoved: function(id) { console.log(id + ' directory is removed'); } }; var listenerId = tizen.content.addChangeListener(listener); // Do some job here and when the listener is not needed anymore remove it // Removes the listener tizen.content.removeChangeListener(listenerId);
setChangeListener
Sets a listener to receive notifications of content changes.
Deprecated. Deprecated since 3.0. Instead, addChangeListener() allows application developers to add a listener and get notified when content is added, removed or updated on a device.
void setChangeListener(ContentChangeCallback changeCallback);
var listener= { oncontentadded: function(content) { console.log(content.contentURI + ' content is added'); }, oncontentupdated: function(content) { console.log(content.contentURI + ' content is updated'); }, oncontentremoved: function(id) { console.log(id + ' is removed'); }, oncontentdiradded: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is added'); }, oncontentdirupdated: function(contentDir) { console.log(contentDir.directoryURI + ' content directory is updated'); }, oncontentdirremoved: function(id) { console.log(id + ' directory is removed'); } }; // Registers to be notified when the content changes tizen.content.setChangeListener(listener);
unsetChangeListener
Unsets the listener to unsubscribe from receiving notifications for content changes.
Deprecated. Deprecated since 3.0. Instead, use removeChangeListener().
void unsetChangeListener();
tizen.content.unsetChangeListener();
getPlaylists
Gets all playlists.
void getPlaylists(PlaylistArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);
var gPlaylists; function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
createPlaylist
Creates a new playlist.
void createPlaylist(DOMString name, PlaylistSuccessCallback successCallback, optional ErrorCallback? errorCallback, optional Playlist? sourcePlaylist);
var gPlaylists; var gPlaylist; function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err.message); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } } function findSuccess(contents) { if (contents.length > 0) { gPlaylist.add(contents[0]); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail); } function findFail(err) { console.log("find FAIL: " + err.message); } function createSuccess(playlist) { console.log("create SUCCESS"); gPlaylist = playlist; tizen.content.find(findSuccess, findFail, null, new tizen.AttributeFilter("type", "EXACTLY", "AUDIO")); } function createFail(err) { console.log("create FAIL: " + err.message); } tizen.content.createPlaylist("My new playlist", createSuccess, createFail);
removePlaylist
Removes a playlist.
void removePlaylist(PlaylistId id, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
var gPlaylists; function removePlaylistSuccess() { console.log("removePlaylist SUCCESS"); } function removePlaylistFail(err) { console.log("removePlaylist FAIL: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } if(gPlaylists.length < 1) { console.log("Please add at least 1 playlist"); return; } console.log("will remove playlist at index [0] name:" + gPlaylists[0].name); tizen.content.removePlaylist(gPlaylists[0].id, removePlaylistSuccess, removePlaylistFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
createThumbnail
Creates a content's thumbnail.
void createThumbnail(Content content, ThumbnailSuccessCallback successCallback, optional ErrorCallback? errorCallback);
function createCB(path) { console.log("The thumbnail path is " + path); } function findCB(contents) { if (contents.length > 0) { tizen.content.createThumbnail(contents[0], createCB); } } tizen.content.find(findCB);
The thumbnail path is /home/owner/share/media/.thumb/phone/.jpg-bed1d5f494830f7a52e1217f1e924aff.jpg
The callback function used to return a list of content objects.
[Callback=FunctionOnly, NoInterfaceObject] interface ContentArraySuccessCallback { void onsuccess(Content[] contents); };
onsuccess
Called when the list of content is retrieved successfully.
void onsuccess(Content[] contents);
The callback function used to return a list of ContentDirectory objects.
[Callback=FunctionOnly, NoInterfaceObject] interface ContentDirectoryArraySuccessCallback { void onsuccess(ContentDirectory[] directories); };
Called when the directory list is retrieved successfully.
void onsuccess(ContentDirectory[] directories);
The callback function used to return content or content directory to scan.
[Callback=FunctionOnly, NoInterfaceObject] interface ContentScanSuccessCallback { void onsuccess(DOMString uri); };
Called when the scanning has been completed.
void onsuccess(DOMString uri);
Remark : This callback is also invoked upon success of the scanDirectory() method since Tizen 2.4. Therefore, the uri parameter may now also be the URI of a ContentDirectory object.
This interface specifies a set of methods that are invoked every time a content change occurs.
[Callback, NoInterfaceObject] interface ContentChangeCallback { void oncontentadded(Content content); void oncontentupdated(Content content); void oncontentremoved(ContentId id); void oncontentdiradded(ContentDirectory contentDir); void oncontentdirupdated(ContentDirectory contentDir); void oncontentdirremoved(ContentDirectoryId id); };
oncontentadded
Called when content is added.
void oncontentadded(Content content);
oncontentupdated
Called when content is updated.
void oncontentupdated(Content content);
oncontentremoved
Called when content is removed.
void oncontentremoved(ContentId id);
oncontentdiradded
Called when a content directory is added.
void oncontentdiradded(ContentDirectory contentDir);
oncontentdirupdated
Called when a content directory is updated.
void oncontentdirupdated(ContentDirectory contentDir);
oncontentdirremoved
Called when a content directory is removed.
void oncontentdirremoved(ContentDirectoryId id);
The ContentDirectory interface provides access to properties of a content directory.
[NoInterfaceObject] interface ContentDirectory { readonly attribute ContentDirectoryId id; readonly attribute DOMString directoryURI; readonly attribute DOMString title; readonly attribute ContentDirectoryStorageType storageType; readonly attribute Date? modifiedDate; };
readonly ContentDirectoryId id
The opaque content directory identifier.
readonly SmartControllerManager directoryURI
The directory path on the device.
readonly SmartControllerManager title
The directory name.
readonly ContentDirectoryStorageType storageType
The type of device storage.
readonly Date modifiedDate nullable
The last modified date for a directory.
The Content interface provides access to the properties of a content item.
[NoInterfaceObject] interface Content { readonly attribute DOMString[] editableAttributes; readonly attribute ContentId id; attribute DOMString name; readonly attribute ContentType type; readonly attribute DOMString mimeType; readonly attribute DOMString title; readonly attribute DOMString contentURI; readonly attribute DOMString[]? thumbnailURIs; readonly attribute Date? releaseDate; readonly attribute Date? modifiedDate; readonly attribute unsigned long size; attribute DOMString? description; attribute unsigned long rating; attribute boolean isFavorite; };
readonly SmartControllerManager editableAttributes
The list of attributes that are editable to the local backend using the update() or updateBatch() method.
readonly ContentId id
The opaque content identifier.
DOMString name
The content name. The initial value is the file name of the content.
readonly ContentType type
The content type.
readonly SmartControllerManager mimeType
The content MIME type.
The content title.
readonly SmartControllerManager contentURI
The URI to access the content.
readonly SmartControllerManager thumbnailURIs thumbnailURIs nullable
The array of content thumbnail URIs.
readonly Date releaseDate nullable
The date when content has been released publicly. If only the release year is known, then the month and date are set to January and 1st respectively.
The last modified date for a content item.
readonly unsigned long size
The file size of the content in bytes.
DOMString description nullable
The content description.
unsigned long rating
The content rating. This value can range from 0 to 10.
boolean isFavorite
Boolean value that indicates whether a content item is marked as a favorite.
The VideoContent interface extends a basic Content object with video-specific attributes.
[NoInterfaceObject] interface VideoContent : Content { attribute SimpleCoordinates? geolocation; readonly attribute DOMString? album; readonly attribute DOMString[]? artists; readonly attribute unsigned long duration; readonly attribute unsigned long width; readonly attribute unsigned long height; };
SimpleCoordinates geolocation nullable
The geographical location where the video has been made.
readonly SmartControllerManager album nullable
The album name to which the video belongs.
readonly SmartControllerManager artists nullable
The list of artists who created the video.
readonly unsigned long duration
The video duration in milliseconds.
readonly unsigned long width
The width of a video in pixels.
readonly unsigned long height
The height of the video in pixels.
The AudioContentLyrics interface provides lyrics for music.
[NoInterfaceObject] interface AudioContentLyrics { readonly attribute AudioContentLyricsType type; readonly attribute unsigned long[] timestamps; readonly attribute DOMString[] texts; };
readonly AudioContentLyricsType type
The type of lyrics, that is, whether they are synchronized with the music.
readonly unsigned unsigned long timestamps
The array of timestamps in milliseconds for lyrics.
If the lyrics are not synchronized (if there is no time information for the lyrics) the array is undefined.
readonly SmartControllerManager texts
The array of lyrics snippets.
If the lyrics are not synchronized, the array has only one member with full lyrics.
The AudioContent interface extends a basic Content object with audio-specific attributes.
[NoInterfaceObject] interface AudioContent : Content { readonly attribute DOMString? album; readonly attribute DOMString[]? genres; readonly attribute DOMString[]? artists; readonly attribute DOMString[]? composers; readonly attribute AudioContentLyrics? lyrics; readonly attribute DOMString? copyright; readonly attribute unsigned long bitrate; readonly attribute unsigned short? trackNumber; readonly attribute unsigned long duration; };
The album name to which the audio belongs.
readonly SmartControllerManager genres nullable
The list of genres to which the audio belongs.
The list of artists who created the audio.
readonly SmartControllerManager composers nullable
The list of composers for the music.
readonly AudioContentLyrics lyrics nullable
The lyrics of a song in an audio file.
readonly SmartControllerManager copyright nullable
The copyright information.
readonly unsigned long bitrate
The audio bitrate in bits per second. By default, this value is 0.
readonly unsigned short trackNumber nullable
The track number if the audio belongs to an album.
The audio duration in milliseconds.
The ImageContent interface extends a basic Content object with image-specific attributes.
[NoInterfaceObject] interface ImageContent : Content { attribute SimpleCoordinates? geolocation; readonly attribute unsigned long width; readonly attribute unsigned long height; attribute ImageContentOrientation orientation; };
The geographical location where the image has been made.
The width of an image in pixels.
The height of an image in pixels.
ImageContentOrientation orientation
The image orientation.
The PlaylistItem interface represents a playlist item.
[NoInterfaceObject] interface PlaylistItem { readonly attribute Content content; };
readonly Content content
Content contained in this playlist item.
The Playlist interface represents a playlist.
[NoInterfaceObject] interface Playlist { readonly attribute PlaylistId id; attribute DOMString name raises(WebAPIException); readonly attribute long numberOfTracks; attribute DOMString? thumbnailURI raises(WebAPIException); void add(Content item) raises(WebAPIException); void addBatch(Content[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void remove(PlaylistItem item) raises(WebAPIException); void removeBatch(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void get(PlaylistItemArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional long? count, optional long? offset) raises(WebAPIException); void setOrder(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void move(PlaylistItem item, long delta, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
readonly PlaylistId id
Identifier of a playlist.
Name of a playlist (case sensitive and unique).
When name is set, the change is recorded in the database.
with error type InvalidValuesError, when assigning an invalid value (e.g. playlist of the same name already exists).
with error type SecurityError, if the application does not have the privilege to change this attribute.
readonly long numberOfTracks
Number of playlist items in the playlist.
DOMString thumbnailURI nullable
Thumbnail URI of a playlist.
By default, this attribute is set to null. When thumbnailURI is set, the change is recorded in the database.
with error type InvalidValuesError, when assigning an invalid value (e.g. if the URI does not start with "file:///").
add
Adds a content item to a playlist.
void add(Content item);
See code example for the createPlaylist() method.
addBatch
Adds tracks to a playlist as a batch, asynchronously.
void addBatch(Content[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
remove
Removes a track from a playlist.
void remove(PlaylistItem item);
var gPlaylists, gItems, gCurPlaylist; function get2Fail(err) { console.log("get items (after remove) failed: " + err); } function get2Success(items) { console.log("Playlist items:"); for(var i = 0; i < items.length ; ++i) { console.log("[" + i + "]: name:" + items[i].content.name); } } function getSuccess(items) { gItems = items; if(gItems.length < 1) { console.log("Please add at least 1 tracks to playlist!"); return; } console.log("Original playlist:"); for(var i = 0; i < gItems.length ; ++i) { console.log("[" + i + "]: name:" + gItems[i].content.name); } console.log("Will remove item at index [0] name:" + gItems[0].content.name); gCurPlaylist.remove(gItems[0]); gCurPlaylist.get(get2Success, get2Fail); } function getFail(err) { console.log("get items failed: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { gPlaylists = playlists; if(gPlaylists.length === 0) { console.log("Please create at least 1 playlist!"); return; } gCurPlaylist = gPlaylists[0]; gCurPlaylist.get(getSuccess, getFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
removeBatch
Removes tracks from a playlist as a batch, asynchronously.
void removeBatch(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
var gPlaylists, gItems, gCurPlaylist; function get2Fail(err) { console.log("get items (after remove batch) failed: " + err); } function get2Success(items) { console.log("Playlist after remove batch:"); for(var i = 0; i < items.length ; ++i) { console.log("[" + i + "]: name:" + items[i].content.name); } } function removeBatchSuccess() { console.log("removeBatch success"); gCurPlaylist.get(get2Success, get2Fail); } function removeBatchFail(err) { console.log("removeBatch failed: " + err); } function getSuccess(items) { gItems = items; if(gItems.length < 4) { console.log("Please add at least 4 tracks to playlist!"); return; } console.log("Original playlist:"); for(var i = 0; i < gItems.length ; ++i) { console.log("[" + i + "]: name:" + gItems[i].content.name); } console.log("Will remove items at index [0](name:" + gItems[0].content.name + ") and at index [2](name:" + gItems[2].content.name + ")"); gCurPlaylist.removeBatch([gItems[2], gItems[0]], removeBatchSuccess, removeBatchFail); } function getFail(err) { console.log("get items failed: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { gPlaylists = playlists; if(gPlaylists.length === 0) { console.log("Please create at least 1 playlist!"); return; } gCurPlaylist = gPlaylists[0]; gCurPlaylist.get(getSuccess, getFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
get
Gets playlist items from a playlist.
void get(PlaylistItemArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional long? count, optional long? offset);
var gPlaylists, gItems, gCurPlaylist; function getSuccess(items) { gItems = items; console.log("Playlist items:"); for(var i = 0; i < items.length ; ++i) { console.log("[" + i + "]: name:" + items[i].name); } } function getFail(err) { console.log("get items failed: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { gPlaylists = playlists; if(gPlaylists.length === 0) { console.log("Please create at least 1 playlist!"); return; } gCurPlaylist = gPlaylists[0]; // To retrieves all playlist items of 'gCurPlaylist' playlist. gCurPlaylist.get(getSuccess, getFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
setOrder
Changes the play order of all playlist items in the playlist.
void setOrder(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
var gPlaylists, gItems, gCurPlaylist, gExpectedOrder; function get2Fail(err) { console.log("get items (after set order) failed: " + err); } function get2Success(items) { console.log("Playlist order after setOrder:"); for(var i = 0; i < items.length ; ++i) { console.log("[" + i + "]: name:" + items[i].content.name); } } function setOrderSuccess() { console.log("set items order SUCCESS"); gCurPlaylist.get(get2Success, get2Fail); } function setOrderFail(err) { console.log("set items order failed: " + err); } function getSuccess(items) { gItems = items; if(gItems.length < 2) { console.log("Please add at least 2 tracks to playlist!"); return; } console.log("Original order:"); for(var i = 0; i < gItems.length ; ++i) { console.log("[" + i + "]: name:" + gItems[i].content.name); } gExpectedOrder = gItems.slice(0); gExpectedOrder.reverse(); console.log("New order:"); for(var i = 0; i < gExpectedOrder.length ; ++i) { console.log("[" + i + "]: name:" + gExpectedOrder[i].content.name); } gCurPlaylist.setOrder(gExpectedOrder, setOrderSuccess, setOrderFail); } function getFail(err) { console.log("get items failed: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { gPlaylists = playlists; if(gPlaylists.length === 0) { console.log("Please create at least 1 playlist!"); return; } gCurPlaylist = gPlaylists[0]; gCurPlaylist.get(getSuccess, getFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
move
Moves the specified item up or down a specified amount in the play order.
move(PlaylistItem item, long delta, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
If current index + delta is:
var gPlaylists, gItems, gCurPlaylist; function get2Fail(err) { console.log("get items (after move item) failed: " + err); } function get2Success(items) { console.log("Playlist order after move:"); for(var i = 0; i < items.length ; ++i) { console.log("[" + i + "]: name:" + items[i].content.name); } } function moveSuccess() { console.log("move item SUCCESS"); gCurPlaylist.get(get2Success, get2Fail); } function moveFail(err) { console.log("move item failed: " + err); } function getSuccess(items) { gItems = items; if(gItems.length < 2) { console.log("Please add at least 2 tracks to playlist!"); return; } console.log("Original order:"); for(var i = 0; i < gItems.length ; ++i) { console.log("[" + i + "]: name:" + gItems[i].content.name); } console.log("Will move item at index [1] (name: " + gItems[1].content.name + ") up by one place (to [0])"); gCurPlaylist.move(gItems[1], -1, moveSuccess, moveFail); gItems.unshift(gItems.splice(1, 1)[0]); } function getFail(err) { console.log("get items failed: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { gPlaylists = playlists; if(gPlaylists.length === 0) { console.log("Please create at least 1 playlist!"); return; } gCurPlaylist = gPlaylists[0]; gCurPlaylist.get(getSuccess, getFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail);
The PlaylistArraySuccessCallback interface specifies a success callback that is invoked when all existing playlists are retrieved successfully.
[Callback=FunctionOnly, NoInterfaceObject] interface PlaylistArraySuccessCallback { void onsuccess(Playlist[] playlists); };
It is used in tizen.content.getPlaylists().
Called when the tizen.content.getPlaylists() method completes successfully.
onsuccess(Playlist[] playlists);
The PlaylistSuccessCallback interface specifies a success callback that is invoked when a new playlist is successfully created.
[Callback=FunctionOnly, NoInterfaceObject] interface PlaylistSuccessCallback { void onsuccess(Playlist playlist); };
It is used in tizen.content.createPlaylist().
Called when the tizen.content.createPlaylist() method completes successfully.
onsuccess(Playlist playlist);
The PlaylistItemArraySuccessCallback interface specifies a success callback that is invoked when a list of playlist items are successfully retrieved.
[Callback=FunctionOnly, NoInterfaceObject] interface PlaylistItemArraySuccessCallback { void onsuccess(PlaylistItem[] items); };
Called when the playlist.get() method completes successfully.
onsuccess(PlaylistItem[] items);
The ThumbnailSuccessCallback interface specifies a success callback that is invoked when a content's thumbnail is successfully created.
[Callback=FunctionOnly, NoInterfaceObject] interface ThumbnailSuccessCallback { void onsuccess(DOMString path); };
Called when the tizen.content.createThumbnail() method completes successfully.
onsuccess(DOMString path);
module Content { enum ContentDirectoryStorageType { "INTERNAL", "EXTERNAL" }; enum ContentType { "IMAGE", "VIDEO", "AUDIO", "OTHER" }; enum AudioContentLyricsType { "SYNCHRONIZED", "UNSYNCHRONIZED" }; enum ImageContentOrientation { "NORMAL", "FLIP_HORIZONTAL", "ROTATE_180", "FLIP_VERTICAL", "TRANSPOSE", "ROTATE_90", "TRANSVERSE", "ROTATE_270" }; typedef DOMString ContentId; typedef DOMString ContentDirectoryId; typedef DOMString PlaylistId; [NoInterfaceObject] interface ContentManagerObject { readonly attribute ContentManager content; }; Tizen implements ContentManagerObject; [NoInterfaceObject] interface ContentManager { void update(Content content) raises(WebAPIException); void updateBatch(Content[] contents, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void getDirectories(ContentDirectoryArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void find(ContentArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional ContentDirectoryId? directoryId, optional AbstractFilter? filter, optional SortMode? sortMode, optional unsigned long? count, optional unsigned long? offset) raises(WebAPIException); void scanFile(DOMString contentURI, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void scanDirectory(DOMString contentDirURI, boolean recursive, optional ContentScanSuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void cancelScanDirectory(DOMString contentDirURI) raises(WebAPIException); ```java void(ContentChangeCallback changeCallback) raises(WebAPIException); void removeChangeListener(long listenerId) raises(WebAPIException); void setChangeListener(ContentChangeCallback changeCallback) raises(WebAPIException); void unsetChangeListener() raises(WebAPIException); void getPlaylists(PlaylistArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void createPlaylist(DOMString name, PlaylistSuccessCallback successCallback, optional ErrorCallback? errorCallback, optional Playlist? sourcePlaylist) raises(WebAPIException); void removePlaylist(PlaylistId id, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void createThumbnail(Content content, ThumbnailSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface ContentArraySuccessCallback { void onsuccess(Content[] contents); }; [Callback=FunctionOnly, NoInterfaceObject] interface ContentDirectoryArraySuccessCallback { void onsuccess(ContentDirectory[] directories); }; [Callback=FunctionOnly, NoInterfaceObject] interface ContentScanSuccessCallback { void onsuccess(DOMString uri); }; [Callback, NoInterfaceObject] interface ContentChangeCallback { void oncontentadded(Content content); void oncontentupdated(Content content); void oncontentremoved(ContentId id); void oncontentdiradded(ContentDirectory contentDir); void oncontentdirupdated(ContentDirectory contentDir); void oncontentdirremoved(ContentDirectoryId id); }; [NoInterfaceObject] interface ContentDirectory { readonly attribute ContentDirectoryId id; readonly attribute DOMString directoryURI; readonly attribute DOMString title; readonly attribute ContentDirectoryStorageType storageType; readonly attribute Date? modifiedDate; }; [NoInterfaceObject] interface Content { readonly attribute DOMString[] editableAttributes; readonly attribute ContentId id; attribute DOMString name; readonly attribute ContentType type; readonly attribute DOMString mimeType; readonly attribute DOMString title; readonly attribute DOMString contentURI; readonly attribute DOMString[]? thumbnailURIs; readonly attribute Date? releaseDate; readonly attribute Date? modifiedDate; readonly attribute unsigned long size; attribute DOMString? description; attribute unsigned long rating; attribute boolean isFavorite; }; [NoInterfaceObject] interface VideoContent : Content { attribute SimpleCoordinates? geolocation; readonly attribute DOMString? album; readonly attribute DOMString[]? artists; readonly attribute unsigned long duration; readonly attribute unsigned long width; readonly attribute unsigned long height; }; [NoInterfaceObject] interface AudioContentLyrics { readonly attribute AudioContentLyricsType type; readonly attribute unsigned long[] timestamps; readonly attribute DOMString[] texts; }; [NoInterfaceObject] interface AudioContent : Content { readonly attribute DOMString? album; readonly attribute DOMString[]? genres; readonly attribute DOMString[]? artists; readonly attribute DOMString[]? composers; readonly attribute AudioContentLyrics? lyrics; readonly attribute DOMString? copyright; readonly attribute unsigned long bitrate; readonly attribute unsigned short? trackNumber; readonly attribute unsigned long duration; }; [NoInterfaceObject] interface ImageContent : Content { attribute SimpleCoordinates? geolocation; readonly attribute unsigned long width; readonly attribute unsigned long height; attribute ImageContentOrientation orientation; }; [NoInterfaceObject] interface PlaylistItem { readonly attribute Content content; }; [NoInterfaceObject] interface Playlist { readonly attribute PlaylistId id; attribute DOMString name raises(WebAPIException); readonly attribute long numberOfTracks; attribute DOMString? thumbnailURI raises(WebAPIException); void add(Content item) raises(WebAPIException); void addBatch(Content[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void remove(PlaylistItem item) raises(WebAPIException); void removeBatch(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void get(PlaylistItemArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional long? count, optional long? offset) raises(WebAPIException); void setOrder(PlaylistItem[] items, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void move(PlaylistItem item, long delta, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [Callback=FunctionOnly, NoInterfaceObject] interface PlaylistArraySuccessCallback { void onsuccess(Playlist[] playlists); }; [Callback=FunctionOnly, NoInterfaceObject] interface PlaylistSuccessCallback { void onsuccess(Playlist playlist); }; [Callback=FunctionOnly, NoInterfaceObject] interface PlaylistItemArraySuccessCallback { void onsuccess(PlaylistItem[] items); }; [Callback=FunctionOnly, NoInterfaceObject] interface ThumbnailSuccessCallback { void onsuccess(DOMString path); }; };