Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.