Archived:How to fetch media files using Symbian C++
Archived: 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
There are many ways to fetch a media file. Here are three of them.
Contents |
1.Using MgFetch::RunL
Headers Required:
#include <mgfetch.h>Libraries:
LIBRARY MgFetch.lib
LIBRARY bafl.lib // for CDesCArrayFlat
Capability required:
CAPABILITY ReadUserData
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);
CleanupStack::PushL(fileArray);
// 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
filename.Append(aPath);
_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 ....


05 Sep
2009
S60 3rd edition documents state that MGFetch does not require any capabilities. This page says that it needs ReadUserData capability. Which is wrong?
-- Symbiatch
Hi Symbiatch,
I have tried using MgFetch without ReadUserData capability. It gives KErrPermissionDenied -46 error. Please find the example application added to reproduce this - So it works only with ReadUserData capability.
-- KiranMudiyam
MgFetch requires DRM capability to work successfully
For MgFetch it's requires DRM capability as mentioned in 3rd Edition SDK i tried it before with some 3rd devices and 3rd FP1 when installed and running on some devices an error message displayed unable to execute for security reasons, this is happen when the MgFetch start creating thumbs and some content on the mobile is DRM.