×
Namespaces

Variants
Actions

如何为音乐播放器生成一个播放列表

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 3rd Edition FP1, S60 3rd Edition FP2
S60 3rd Edition FP2
S60 3rd Edition FP1

文章
翻译:
hoolee
最后由 hamishwillee 在 14 Jun 2013 编辑

详细描述

S60标准的音乐播放器支持M3U格式的播放列表(Moving Picture Experts Group Audio Layer 3 Uniform Resource Locator)

这样我们可以通过程序来生成列表。我们需要将每个track的文件名写入到播放列表中(M3U文件),文件路径可以是相对路径

解决方案

M3U文件示例:

#EXTM3U
Audio1.mp3
Audio2.mp3
Audio3.mp3
Audio4.mp3

生成一个.m3u后缀的文件,并将歌曲名和路径使用RFile::Write()写入。我们需要采用UTF8格式

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

注意

音乐播放器需要刷新一下,才能显示

This page was last modified on 14 June 2013, at 09:04.
98 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.

×