| ID | CS001245 | Creation date | December 18, 2008 |
| Platform | S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Web Runtime (WRT) | Subcategory | Multimedia |
| Keywords (APIs, classes, methods, functions): device.getServiceObject(), Service.MediaManagement.GetList() |
This code snippet shows how to asynchronously get a list of images using the Media Management Platform Service for Web Runtime introduced in S60 5th Edition.
To obtain access to the service object for the Media Management Service API, the device.getServiceObject("Service.MediaManagement", "IDataSource") method is used.
<div id="bodyContent" class="bodyContent">
<select size="5" id="imageList" onclick="show();"></select><br />
<img id="imageShow" alt="" src="" />
</div>
//Object available through a Service API. Declare service object,
//that is used to access the multimedia services.
var multimediaServiceObject = null;
window.onload = init;
// Initializes the widget
function init() {
try {
//Getting service object for multimedia.
multimediaServiceObject =
device.getServiceObject("Service.MediaManagement", "IDataSource");
//Setting file criteria.
var criteria = new Object();
criteria.Type = "FileInfo";
criteria.Filter = new Object();
criteria.Filter.FileType = "Image";
criteria.Sort = new Object();
criteria.Sort.Key = "FileSize";
//Asynchronous function for fetching files.
result =
multimediaServiceObject.IDataSource.GetList(criteria, callback);
} catch( exception ) {
alert("initialize error: " + exception);
}
}
/**
* A callback function used to handle results of fetching multimedia files.
* @param transId A number representing the transaction that called the
* callback
* @param eventCode A number representing the callback return status
* @param result An object for holding the callback return value
*/
function callback(transId, eventCode, result) {
if(result.ErrorCode != 0) {
alert("Error in creating file list:" + result.ErrorCode);
return;
}
createFileList(result.ReturnValue);
document.getElementById("imageList").options[0].focus();
}
/**
* Creates a list item for every multimedia file in "iterator".
* @param iterator The list of files
*/
function createFileList(iterator) {
var imageList = document.getElementById("imageList");
//Reset to set pointer to the first element.
iterator.reset();
var item;
//Cleaning the file list.
while (imageList.length != 0) {
imageList.remove(0);
}
while ((item = iterator.getNext()) != undefined) {
var node = document.createElement("option");
//Value of option consists of the full path.
node.value = item.FileNameAndPath;
node.appendChild(document.createTextNode(item.FileName +
item.FileExtension));
imageList.appendChild(node);
}
}
/**
* Shows the selected image.
*/
function show() {
var imageList = document.getElementById("imageList");
for(var i = 0; i < imageList.options.length; i++) {
if (imageList.options[i].selected) {
document.getElementById("imageShow").src =
imageList.options[i].value;
}
}
}
You can view the source file and executable application in the attached ZIP archive. The archive is available for download at Media:Loading_images_in_WRT.zip.
No related wiki articles found