Created
November 15, 2017 11:35
-
-
Save engr-erum/7697d0084a3706d5c75a56a7f9608294 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
playAudio(); | |
ivActionPlayVideo.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (mediaType == 1) { | |
if (!mediaPlayer.isPlaying()) { | |
videoView.setVisibility(View.INVISIBLE); | |
ivViewTracker.setVisibility(View.VISIBLE); | |
ivActionPlayVideo.setVisibility(View.VISIBLE); | |
ivActionPlayVideo.setImageDrawable(ContextCompat.getDrawable(DetailActivityAudio.this, android.R.drawable.ic_media_pause)); | |
startAudio(); | |
} else { | |
videoView.setVisibility(View.GONE); | |
ivViewTracker.setVisibility(View.VISIBLE); | |
ivActionPlayVideo.setVisibility(View.VISIBLE); | |
ivViewTracker.setBackgroundResource(R.drawable.audio_detail_place_holder); | |
ivActionPlayVideo.setImageDrawable(ContextCompat.getDrawable(DetailActivityAudio.this, android.R.drawable.ic_media_play)); | |
if (mediaPlayer != null) { | |
mediaPlayer.pause(); | |
audioLength = mediaPlayer.getCurrentPosition(); | |
} | |
} | |
} | |
} | |
}); | |
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(); | |
} catch (IllegalArgumentException e) { | |
e.printStackTrace(); | |
} catch (IllegalStateException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} else { | |
Log.e(DetailActivityAudio.class.getName(), "mediaFileUrl:" + mediaFileUrl); | |
} | |
} | |
private void startAudio() { | |
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | |
public void onPrepared(MediaPlayer mp) { | |
//mp.seekTo(audioLength); | |
mp.start(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment