Tutorial by Examples

MediaPlayer class can be used to control playback of audio/video files and streams. Creation of MediaPlayer object can be of three types: Media from local resource MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.resource); mediaPlayer.start(); // no need to call prepare(); create...
The MediaPlayer$prepare() is a blocking call and will freeze the UI till execution completes. To solve this problem, MediaPlayer$prepareAsync() can be used. mMediaPlayer = ... // Initialize it here mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){ @Override public ...
This example demonstrates how to fetch the URI's of system ringtones (RingtoneManager.TYPE_RINGTONE): private List<Uri> loadLocalRingtonesUris() { List<Uri> alarms = new ArrayList<>(); try { RingtoneManager ringtoneMgr = new RingtoneManager(getActivi...
Audio stream types There are different profiles of ringtone streams. Each one of them has it's different volume. Every example here is written for AudioManager.STREAM_RING stream type. However this is not the only one. The available stream types are: STREAM_ALARM STREAM_DTMF STREAM_MUSIC STR...
public class SoundActivity extends Activity { private MediaPlayer mediaPlayer; ProgressBar progress_bar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tool_sound); ...
This is an example how to get the play an audio file which you already have on your pc/laptop .First create a new directory under res and name it as raw like this copy the audio which you want to play into this folder .It may be a .mp3 or .wav file. Now for example on button click you want to pl...

Page 1 of 1