[Android] Video player: Avoid IO from main thread
Geoffrey Métais
git at videolan.org
Mon Feb 11 16:33:15 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 11 15:42:09 2019 +0100| [27b96b97231321107e9b5573ae235fac977cd0a7] | committer: Geoffrey Métais
Video player: Avoid IO from main thread
> https://code.videolan.org/videolan/vlc-android/commit/27b96b97231321107e9b5573ae235fac977cd0a7
---
.../vlc/gui/video/VideoPlayerActivity.java | 54 +++++++++++++---------
1 file changed, 33 insertions(+), 21 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index b00a9c9b9..6689c061c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -133,6 +133,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.ViewStubCompat;
import androidx.databinding.BindingAdapter;
import androidx.databinding.DataBindingUtil;
+import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
@@ -2877,29 +2878,40 @@ public class VideoPlayerActivity extends AppCompatActivity implements IPlaybackS
mIsNavMenu = false;
mMenuIdx = -1;
- final MediaPlayer.Title[] titles = mService.getTitles();
- if (titles != null) {
- final int currentIdx = mService.getTitleIdx();
- for (int i = 0; i < titles.length; ++i) {
- final MediaPlayer.Title title = titles[i];
- if (title.isMenu()) {
- mMenuIdx = i;
- break;
- }
- }
- mIsNavMenu = mMenuIdx == currentIdx;
- }
+ WorkersKt.runIO(new Runnable() {
+ @Override
+ public void run() {
+ final MediaPlayer.Title[] titles = mService.getTitles();
+ WorkersKt.runOnMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (isFinishing() || !getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return;
+ if (titles != null) {
+ final int currentIdx = mService.getTitleIdx();
+ for (int i = 0; i < titles.length; ++i) {
+ final MediaPlayer.Title title = titles[i];
+ if (title.isMenu()) {
+ mMenuIdx = i;
+ break;
+ }
+ }
+ mIsNavMenu = mMenuIdx == currentIdx;
+ }
- if (mIsNavMenu) {
- /*
- * Keep the overlay hidden in order to have touch events directly
- * transmitted to navigation handling.
- */
- hideOverlay(false);
- } else if (mMenuIdx != -1) setESTracks();
+ if (mIsNavMenu) {
+ /*
+ * Keep the overlay hidden in order to have touch events directly
+ * transmitted to navigation handling.
+ */
+ hideOverlay(false);
+ } else if (mMenuIdx != -1) setESTracks();
- UiTools.setViewVisibility(mNavMenu, mMenuIdx >= 0 && mNavMenu != null ? View.VISIBLE : View.GONE);
- supportInvalidateOptionsMenu();
+ UiTools.setViewVisibility(mNavMenu, mMenuIdx >= 0 && mNavMenu != null ? View.VISIBLE : View.GONE);
+ supportInvalidateOptionsMenu();
+ }
+ });
+ }
+ });
}
@Override
More information about the Android
mailing list