简体   繁体   中英

Media file can not be switched and played

I am trying to play a music file on S60 5th edition with the following code:

_LIT(KMusicFilename, "C:\\Data\\Music.mp3");

 TApaTaskList iTaskList(CCoeEnv::Static()->WsSession());
 TBool iExists;
 TApaTask iApaTask = iTaskList.FindApp(TUid::Uid(0x102072C3));
 iExists = iApaTask.Exists();
 if(iExists)
   {
   // Music player already running
   iApaTask.SwitchOpenFile(KMusicFilename);
   iApaTask.BringToForeground();
   }
 else
   {
   // music player is not running and needs to be launched
   RApaLsSession iAplsSession;
   User::LeaveIfError(iAplsSession.Connect());
   TThreadId thread;
   iAplsSession.StartDocument( KMusicFilename, 
                               thread, 
                               RApaLsSession::ESwitchFiles );
   iAplsSession.Close();
   }

The problem is that this code sample does not work if the music player is already running. The media file that was already playing keeps playing, the function SwitchOpenFile does not have any effect on it.

Is there a workaround for this?

Thank you.

I'm not sure why it doesn't work, but one thing I notice about your code: this call:

iApaTask.SwitchOpenFile(KMusicFilename);

does not check the error code; see if you get an non-zero error code and this may help determine what the problem is. (The same applies to the iAplsSession.StartDocument(...) call).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM