views:

57

answers:

1

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.

A: 

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).

MathewI
I did check the return value while debugging, and it is KErrNone.
Bojan Milankovic