Starting the Media Player

Creating a MediaPlayer for this audio file is straightforward. We instantiate a MediaPlayer object using the static method create, passing in this as a Context (which Activity is descended from) and the generated resource ID of the audio file.

MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.goodmorningandroid);

Following that, we simply call the start method on the MediaPlayer object to play it. mediaPlayer.start();

Was this article helpful?

0 0

Post a comment