PreviewMediaFragment: stop video when stopping activity, and don't recreate existing player

This avoids multiple instances of the player opening when minimizing the app, for example.

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey Vilas 2022-02-18 17:09:36 +01:00
parent c9018f8ba6
commit 686748dda2
No known key found for this signature in database
GPG key ID: 2585783189A62105

View file

@ -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();