Created
January 2, 2018 05:10
-
-
Save engr-erum/190b78af3fefb5d998486f49240143be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void playAudio() { | |
if (mediaPlayer == null) { | |
mediaPlayer = new MediaPlayer(); | |
} | |
if (!TextUtils.isEmpty(mediaFileUrl)) { | |
try { | |
mediaPlayer.reset(); | |
mediaPlayer.setDataSource(mediaFileUrl); | |
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); | |
mediaPlayer.prepare(); | |
setButtons(); | |
} catch (IllegalArgumentException e) { | |
e.printStackTrace(); | |
} catch (IllegalStateException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
private void setButtons() | |
{ | |
if (mediaPlayer != null) { | |
if (!mediaPlayer.isPlaying()) { | |
ivActionPlayVideo.setVisibility(View.VISIBLE); | |
ivActionPlayVideo.setImageDrawable(ContextCompat.getDrawable(AudioDetailActivity.this, android.R.drawable.ic_media_pause)); | |
if (audioLength > 0) { | |
mediaPlayer.seekTo(audioLength); | |
} | |
mediaPlayer.start(); | |
ivViewTracker.setVisibility(View.GONE); | |
ivRecordingGifMic.setVisibility(View.VISIBLE); | |
} else { | |
ivActionPlayVideo.setVisibility(View.VISIBLE); | |
ivActionPlayVideo.setImageDrawable(ContextCompat.getDrawable(AudioDetailActivity.this, android.R.drawable.ic_media_play)); | |
if (mediaPlayer != null && mediaPlayer.isPlaying()) { | |
mediaPlayer.pause(); | |
audioLength = mediaPlayer.getCurrentPosition(); | |
} | |
ivViewTracker.setVisibility(View.VISIBLE); | |
ivRecordingGifMic.setVisibility(View.GONE); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment