From c4953363601ceec4185c020f78c959fe3812d0ca Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:58:39 -0400 Subject: Fix https://github.com/Docile-Alligator/Infinity-For-Reddit/issues/1674 the audio does not stop after closing a video. --- .../infinityforreddit/activities/ViewVideoActivity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 891bb99f..6be51742 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -31,6 +31,7 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.OptIn; import androidx.appcompat.app.ActionBar; @@ -347,6 +348,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe } binding.getRoot().setOnDragDismissedListener(dragDirection -> { + player.stop(); int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down; finish(); overridePendingTransition(0, slide); @@ -648,6 +650,15 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe player.setMediaSource(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(MediaItem.fromUri(mVideoUri))); preparePlayer(savedInstanceState); } + + getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + player.stop(); + setEnabled(false); + getOnBackPressedDispatcher().onBackPressed(); + } + }); } private void preparePlayer(Bundle savedInstanceState) { -- cgit v1.2.3