Loading images in Symbian Web Runtime
Article Metadata
Code Example
Source file: Media:Loading images in WRT.zip
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
Article
Keywords: device.getServiceObject(), Service.MediaManagement.GetList()
Created: ivruban
(10 Dec 2008)
Last edited: hamishwillee
(04 Oct 2012)
Contents |
Overview
This code snippet shows how to asynchronously get a list of images using the Media Management Platform Service for Symbian Web Runtime. This service was 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.
Source: Relevant HTML components
<div id="bodyContent" class="bodyContent">
<select size="5" id="imageList" onclick="show();"></select><br />
<img id="imageShow" alt="" src="" />
</div>
Source: imageviewer.js
//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;
}
}
}
Postconditions
- When the snippet is started, all available image names are loaded into the list box.
- When clicking on the image name, the image content is loaded and displayed.
Supplementary material
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.


Using this example on 3rd Edition FP2 Emulator, I get the error.
Initialize error, Can't find the variable device.
Also no images are shown in the listbox.
Is the example prepared to run on the device only?
croozeus 16:01, 11 December 2008 (EET)
Oh I just realized that this API is supported only in 5th Edition, so I tried it on 5th Edition on SDK.
No Error in the SDK but its not working more than the start page. The drop downlist is not clickable.
croozeus 16:24, 11 December 2008 (EET)