Archived:How to fetch media files using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code ExampleCompatibilityArticle
Created: kiranmudiyam (29 Jun 2007)
Last edited: hamishwillee (21 Jun 2012)

There are many ways to fetch a media file. Here are three of them.


1.Using MgFetch::RunL

Headers Required:

#include <mgfetch.h>


LIBRARY MgFetch.lib
LIBRARY bafl.lib // for CDesCArrayFlat

Capability required:


MgFetch::RunL will fetch media files in C:\Data and E:\Data paths inherently.There is no need to mention the path anywhere.

We can query for the media types given in mediafiletypes.hrh

void BrowseUsingMGFetchL(TMediaFileType aMediaType)
// Create array of descriptors for the selected files
CDesCArrayFlat* fileArray = new (ELeave) CDesCArrayFlat(5);
// Open the dialog.
TBool ret = MGFetch::RunL(
*fileArray, // When dialog is closed, fileArray contains selected files
aMediaType, // Displays only media files of type aMediaType
ETrue, // single or multiple file selection
NULL // Pointer to class implementing MMGFetchVerifier;
// when user has selected file(s),
// MMGFetchVerifier::VerifySelectionL is called.
// "ret" is true, if user has selected file(s)
if( ret )
// Open the first selected file into default application
CleanupStack::PopAndDestroy(); // fileArray

Example Project: File:MgFetch.zip

2.Using CAknFileSelectionDialog::RunDlgLD

Headers Required:

#include <caknfileselectiondialog.h> 
#include <pathinfo.h>

Library Needed:

LIBRARY CommonDialogs.lib // for CAknFileSelectionDialog
LIBRARY PlatformEnv.lib // for pathinfo

CAknFileSelectionDialog::RunDlgLD launches file selection dialogue having the media files in the specified folder. Pathinfo class gives the system paths for media files.

void BrowseUsingAknSelectionDlgL(const TFileName& aPath)
TFileName filename;
// Create default filename. (contains only the folder,
// e.g. C:\Data\Images\) This is used as a starting folder for browsing image files.
filename.Append(PathInfo::PhoneMemoryRootPath()); //Use MemoryCardRootPath() for MMC
_LIT(KDialogTitle, "Browse files");
TBool ret = CAknFileSelectionDialog::RunDlgLD(
filename, // on return, contains the selected file's name
PathInfo::PhoneMemoryRootPath(), // default root path for browsing
KDialogTitle, // Dialog's title
NULL // Pointer to class implementing
// MAknFileSelectionObserver.
// "ret" is true, if user has selected a file
if( ret )
// Open the selected file into default application

Example Project: File:FileFetcher.zip

3.Using native Media Gallery application's UID

The following code launches the native media gallarey application and by changing the KMediaGalleryCmdMoveFocusTo, you can select the media type.

// The native Media Gallery application's UID in S60 platform 2nd Edition FP1 
// (Symbian OS v7.0s) and older
#define KMediaGalleryUID3PreFP1 0x101f4d8f
// The native Media Gallery application's UID in S60 platform 2nd Edition FP2
// (Symbian OS v8.0a) and newer, including 3rd Edition
#define KMediaGalleryUID3PostFP1 0x101f8599
#define KMediaGalleryListViewUID 0x00000001
#define KMediaGalleryCmdMoveFocusTo 0x00000001
TVwsViewId id = TVwsViewId( TUid::Uid(KMediaGalleryUID3PostFP1),
TUid::Uid(KMediaGalleryListViewUID) );
ActivateViewL( id, TUid::Uid( KMediaGalleryCmdMoveFocusTo ),KNullDesC8);
// To switch to the images view, you can use:
#define KMediaGalleryCmdMoveFocusTo 0x00000002
// To switch to the videos view, you can use:
#define KMediaGalleryCmdMoveFocusTo 0x00000003 ....

Example Project


Related Resources

S60 Platform: FileList Example

This page was last modified on 21 June 2012, at 06:02.
67 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.