11. Playing Audio #

Created Wednesday 06 January 2021

As we are learning a new language, it is crucial to learn the correct prounounciation. We’ll add audio to buttons to make this happen.

For this task, we’ll research and come up with a solution on our own.

Approach 1 #

The Android multimedia framework includes support for playing a variety of common media types like audio, video and images. It can do so from media files stored in application’s raw resources (res/res), from files in the filesystem, or from a data stream arriving over a network connection.

The MediaPlayer class is used for media playback. MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1); mp.start(); // Audio

// Other methods
mp.isPlaying();
mp.stop();

Note: AudioManager class is for managing audio volume, bluetooth etc. It does not play audio per se.

Approach 2 #

Using the AudioManager class