Hey, I tried playing the sound program again today and finally succeeded.
Player. h
# Ifndef
Player_h _
# Define player_h _
# Include
<Mdaaudiosampleplayer. h>
# Include
<MDA/common/audio. h>
# Include
<MMF/common/mmfutilities. h>
# Include <e32base. h>
Class
Cfirstfuckcontainer;
Class cplayer: Public daaudioplayercallback, public
Cbase
{
Enum tmystate
{
Einitialising,
Eplaying,
Eprepared
};
Public:
Void createplayerl (const tdesc & afilename );
Void
Playsound ();
Void stopsound ();
Void pausesound ();
~ Cplayer ();
Void mapcinitcomplete (tint aerror, const
Ttimeintervalmicroseconds & aduration );
Void mapcplaycomplete (tint
Aerror );
Void setcontainer (ccoecontrol * acontainer );
Cplayer ();
PRIVATE:
Cmdaaudioplayerutility *
IPlayer;
Tmystate istate;
Cfirstfuckcontainer * icontainer;
};
# Endif/* player_h _*/
Player. cpp
# Include
<Coecntrl. h>
# Include <eiklabel. h>
# Include
<Aknutils. h>
# Include "Player. H"
# Include
"Firstfuckcontainer. H"
Cplayer: cplayer ()
{
}
Cplayer ::~ Cplayer ()
{
If (iPlayer)
{
Delete iPlayer;
IPlayer = NULL;
}
}
Void cplayer: setcontainer (ccoecontrol * acontainer)
{
Icontainer = static_cast <cfirstfuckcontainer *> (acontainer );
}
Void cplayer: createplayerl (const tdesc & afilename)
{
Tfilename filename (afilename );
User: leaveiferror (
Completewithapppath (filename ));
IPlayer =
Cmdaaudioplayerutility: newfileplayerl (filename, * This );
Istate =
Einitialising;
}
Void cplayer: pausesound ()
{
If
(Istate = eplaying)
{
If (iPlayer-> pause () =
Kerrnone)
{
Istate = eprepared;
Ceiklabel * label =
Static_cast <ceiklabel *> (icontainer-> componentcontrol (0); // This label is only used to display prompts.
Label-> settextl (_ L ("player is paused "));
Label-> setextenttowholescreen ();
Label-> drawdeferred ();
}
}
}
Void
Cplayer: playsound ()
{
If (istate = eprepared)
{
IPlayer-> setvolume (iPlayer-> maxvolume ());
IPlayer-> play ();
Istate = eplaying;
Ceiklabel
* Ilabel;
Ilabel = static_cast <ceiklabel *> (
Icontainer-> componentcontrol (0 ));
Ilabel-> settextl (_ L ("player
Is playing "));
Ilabel-> setextenttowholescreen ();
Ilabel-> drawdeferred ();
}
}
Void
Cplayer: stopsound ()
{
If (istate = eplaying)
{
IPlayer-> stop ();
Istate = eprepared;
Ceiklabel *
Label =
Static_cast <ceiklabel *> (icontainer-> componentcontrol (0 ));
Label-> settextl (_ L ("player is stoped "));
Label-> setextenttowholescreen ();
Label-> drawdeferred ();
}
}
Void cplayer: mapcinitcomplete (tint aerror,
Const ttimeintervalmicroseconds & aduration)
{// Load the sound file here
If (aerror =
Kerrnone)
{
Istate = eprepared;
Ceiklabel * label =
Static_cast <ceiklabel *> (icontainer-> componentcontrol (0 ));
Label-> settextl (_ L ("player is ready "));
Label-> setextenttowholescreen ();
Label-> drawdeferred ();
// Playsound ();
}
}
Void cplayer: mapcplaycomplete (tint aerror)
{
If (aerror = kerrnone)
{
Istate = eprepared;
Ceiklabel * label =
Static_cast <ceiklabel *> (icontainer-> componentcontrol (0 ));
Label-> settextl (_ L ("player is finished "));
Label-> setextenttowholescreen ();
Label-> drawdeferred ();
}
}