Game Development Reference
In-Depth Information
//Creates a MediaPlayer for a given resource id (background music)
mediaPlayer
= MediaPlayer.
create
(RaccoonRob.
this
, R.raw.
back
);
//Sets the player to be looping
mediaPlayer
.setLooping(
true
);
Then, implement
playMedia(), pauseMedia(),
and
stopMedia()
methods as follows:
//Plays the specified media
public void
playMedia(){
try
{
if
(!mediaPlayer.isPlaying()) mediaPlayer.start();
}
catch
(Exception e){}
}
//Pauses the specified media
public void
pauseMedia(){
try
{
if
(mediaPlayer.isPlaying()) mediaPlayer.pause();
}
catch
(Exception e){}
}
//Stops the specified media
public void
stopMedia(){
try
{
if
(mediaPlayer.isPlaying()) {
mediaPlayer.stop();
}
mediaPlayer =
null
;
}
catch
(Exception e){}
}
Search WWH ::
Custom Search