Namespaces
Variants
Actions

Loading images in Symbian Web Runtime

Jump to: navigation, search
Article Metadata

Code Example
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.

This page was last modified on 4 October 2012, at 08:26.
245 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved