You Are Here:

Community: Wiki

This page was last modified on 20 January 2009, at 07:19.

CS001245 - Loading images in WRT

From Forum Nokia Wiki



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()

Overview

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.

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.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5ffetchE5fmediaE5ffilesX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ