minor refactoring

This commit is contained in:
tibbi 2016-10-25 20:34:09 +02:00
parent 07b60e0afb
commit 37bda0c72e

View file

@ -190,25 +190,30 @@ public class VideoFragment extends ViewPagerFragment
mTimeHolder.startAnimation(animation); mTimeHolder.startAnimation(animation);
} }
private void pauseVideo() {
if (mIsPlaying) {
togglePlayPause();
}
}
private void togglePlayPause() { private void togglePlayPause() {
if (getActivity() == null) if (getActivity() == null || !isAdded())
return; return;
mIsPlaying = !mIsPlaying; mIsPlaying = !mIsPlaying;
if (mIsPlaying) { if (mIsPlaying) {
playVideo();
} else {
pauseVideo();
}
}
private void playVideo() {
mIsPlaying = true;
if (mMediaPlayer != null) { if (mMediaPlayer != null) {
mMediaPlayer.start(); mMediaPlayer.start();
} }
mPlayOutline.setImageDrawable(null); mPlayOutline.setImageDrawable(null);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else { }
private void pauseVideo() {
mIsPlaying = false;
if (mMediaPlayer != null) { if (mMediaPlayer != null) {
mMediaPlayer.pause(); mMediaPlayer.pause();
} }
@ -216,7 +221,6 @@ public class VideoFragment extends ViewPagerFragment
mPlayOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big)); mPlayOutline.setImageDrawable(getResources().getDrawable(R.mipmap.play_outline_big));
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} }
}
private void initMediaPlayer() { private void initMediaPlayer() {
if (mMediaPlayer != null) if (mMediaPlayer != null)