Playing Sound of Symbian Study Notes 20

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.