Skip to content

Instantly share code, notes, and snippets.

@MohammadSamandari
Created April 1, 2019 09:46
Show Gist options
  • Save MohammadSamandari/f41155cad0885890ab21a341ef7f7eb6 to your computer and use it in GitHub Desktop.
Save MohammadSamandari/f41155cad0885890ab21a341ef7f7eb6 to your computer and use it in GitHub Desktop.
Working with Media Player
// Defining a Media Player:
MediaPlayer mediaPlayer;
// Giving the Media Player a sound to play
mediaPlayer =MediaPlayer.create(this,R.raw.music);
// Getting lenght of file in media player.
int musicLength = mediaPlayer.getDuration();
// getting the current position of sound while playing
int curPosition = mediaPlayer.getCurrentPosition();
// Moving sound to a certain time and playing from there.
mediaPlayer.seekTo(progress);
// Stating the Play of sound
mediaPlayer.start();
// Pauseing the Play of Sound.
mediaPlayer.pause();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment