Archived:How to create a playlist for the music player using Symbian C++
Article Metadata
Tested with
Compatibility
Article
Contents |
Overview
This article provides the way to create a playlist for the standard S60 music player.
Description
The standard S60 mMusic player supports playlists in the M3U format (Moving Picture Experts Group Audio Layer 3 Uniform Resource Locator). So, to create playlist programmatically, we need to write an M3U file with the file names of each track in the playlist. File paths can be either absolute or relative to the M3U file.
Solution
The sample M3U file:
#EXTM3U Audio1.mp3 Audio2.mp3 Audio3.mp3 Audio4.mp3
Create a file with the extension .m3u and write the song names and paths using RFile::Write(). We need to write into the m3u file in UTF8 format (use CnvUtfConverter::ConvertFromUnicodeToUtf8()).
//Creating a pre-defined playlist
RFile file;
TInt nRetVal;
TInt err;
RFs fs;
TBuf<500> string;
//Header
string.Copy(_L("#EXTM3U\n"));
//Songs relative paths
string.Append(_L("song1.mp3\n"));
string.Append(_L("song2.mp3\n"));
string.Append(_L("song3.mp3"));
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
_LIT(KLogFile,"c:\\data\\MyPlayList.m3u");
err = file.Create(fs, KLogFile, EFileWrite);
if( err == KErrAlreadyExists)
file.Open(fs, KLogFile, EFileWrite);
TPtrC8 representation((TUint8*)(&string)->Ptr(), (&string)->Size());
TInt pos;
nRetVal = file.Size(pos);
TBuf8<500> stringutf;
CnvUtfConverter::ConvertFromUnicodeToUtf8(stringutf, string);
nRetVal = file.Write(stringutf);
nRetVal = file.Flush();
file.Close();
CleanupStack::PopAndDestroy();
Note
The music player needs to be refreshed in order to show the playlist in the music player's playlist library.
Related article
M3U wiki page[1]


This article help people that want to know how one can create a m3u playlist for the default music player. The source code lacks a bit more comments, but is simple and easy to undertand.
--ramiroluz