diff --git a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index d356dcd68d..d351926b4f 100644 --- a/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -305,9 +305,12 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene // bind to any existing player mediaPlayerServiceConnection.bind(); - exoPlayer = new ExoPlayer.Builder(requireContext()).build(); + if (exoPlayer == null) { + exoPlayer = new ExoPlayer.Builder(requireContext()).build(); + } binding.exoplayerView.setPlayer(exoPlayer); + LinearLayout linearLayout = binding.exoplayerView.findViewById(R.id.exo_center_controls); if (linearLayout.getChildCount() == 5) { @@ -579,10 +582,14 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene @Override public void onStop() { Log_OC.v(TAG, "onStop"); - if (MimeTypeUtil.isAudio(getFile()) && !mediaPlayerServiceConnection.isPlaying()) { + final OCFile file = getFile(); + if (MimeTypeUtil.isAudio(file) && !mediaPlayerServiceConnection.isPlaying()) { stopAudio(); + } else if (MimeTypeUtil.isVideo(file) && exoPlayer.isPlaying()) { + savedPlaybackPosition = exoPlayer.getCurrentPosition(); + exoPlayer.pause(); } - + mediaPlayerServiceConnection.unbind(); toggleDrawerLockMode(containerActivity, DrawerLayout.LOCK_MODE_UNLOCKED); super.onStop();