Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(player): prioritize desktop players over android intent in graphical sessions

Samir Hossains7695ae8e0933
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0220a55..9e6d69d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
- Added `search_exhausted` tracking in `src/tui/state.rs` and `src/tui/app/requests.rs`, stopping pagination crawls when provider search returns fewer than 15 items or zero query-matching results.
- Preserved stable card slot positions during search pagination in `src/tui/app/requests.rs` by appending subsequent page items to the list rather than re-sorting the entire array out from under the cursor.
- **Media Playback & Buffering Engine**:
+ - Prioritized native desktop media players (`mpv`, `VLC`) over Android intent openers in `src/player.rs` when an active X11/Wayland display server (`$DISPLAY`, `$WAYLAND_DISPLAY`) is detected, preventing Ubuntu Xfce (udroid/PRoot) and Termux:X11 desktop sessions from dispatching playback to external Android app choosers.
- Reduced `mpv` and `IINA` cache-pause wait penalty from 8 seconds to 2 seconds (`--cache-pause-wait=2`) and disabled startup cache pause (`--cache-pause-initial=no`) in `src/player.rs`, preventing multi-second playback stalls on minor network dips.
- Replaced aggressive VLC buffering flags (`--network-caching=10000`, `--adaptive-logic=nearoptimal`) with `--network-caching=3000` and `--adaptive-logic=predictive` in `src/player.rs` to stop demuxer stream restarts and 10-second stall loops.
- Enabled HTTP/1.1 persistent connections (`Keep-Alive`) across DASH segment streaming in `src/proxy.rs`, eliminating recurring TCP handshake overhead.
diff --git a/docs/players.md b/docs/players.md
index 90e2abb..aa1a6d4 100644
--- a/docs/players.md
+++ b/docs/players.md
@@ -12,8 +12,9 @@ Players are detected in priority order and cached across runs:
- Searches `$PATH`, `~/.local/bin`, Flatpak exports (`io.mpv.Mpv`, `org.videolan.VLC`), and Snap.
- **Windows**: `mpv` → `VLC`
- Searches `%LOCALAPPDATA%`, `Program Files`, WinGet packages, Scoop shims, Chocolatey, and Windows Registry `App Paths`.
-- **Android / Termux**: `Android Intent`
- - Dispatches to external video players via `termux-open` or `am start`.
+- **Android / Termux**: `Android Intent` (headless CLI) or `mpv` → `VLC` → `Android Intent` (graphical X11/Wayland desktop)
+ - In headless terminal environments without an active display server, dispatches directly to external Android media apps via `termux-open` or `am start`.
+ - In graphical environments with an active display server (`$DISPLAY` or `$WAYLAND_DISPLAY`, such as Xfce in udroid/PRoot or Termux:X11), native desktop players (`mpv`/`VLC`) are prioritized so playback opens in a desktop window.
You can set a default player via `/settings` (Media Player), or override it with the `MOVIEBOX_PLAYER` environment variable.
diff --git a/src/player.rs b/src/player.rs
index 26b1d58..5098915 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -53,11 +53,17 @@ impl PlayerKind {
}
}
+pub fn has_graphical_display() -> bool {
+ std::env::var("DISPLAY").is_ok_and(|v| !v.trim().is_empty())
+ || std::env::var("WAYLAND_DISPLAY").is_ok_and(|v| !v.trim().is_empty())
+}
+
pub fn detect() -> Vec<PlayerKind> {
let mut players = Vec::new();
let is_termux = crate::updater::artifact::is_termux_environment();
- if is_termux && !android_openers().is_empty() {
+ let has_gui = has_graphical_display();
+ if is_termux && !has_gui && !android_openers().is_empty() {
players.push(PlayerKind::AndroidIntent);
}
@@ -74,7 +80,7 @@ pub fn detect() -> Vec<PlayerKind> {
players.push(PlayerKind::Vlc);
}
- if !is_termux && !android_openers().is_empty() {
+ if (!is_termux || has_gui) && !android_openers().is_empty() {
players.push(PlayerKind::AndroidIntent);
}
@@ -1942,4 +1948,42 @@ mod tests {
Some("http://127.0.0.1:4567/proxy/manifest.mpd")
);
}
+
+ #[test]
+ fn test_has_graphical_display_detection() {
+ let _lock = ENV_MUTEX.lock().unwrap();
+ let orig_display = std::env::var("DISPLAY").ok();
+ let orig_wayland = std::env::var("WAYLAND_DISPLAY").ok();
+
+ unsafe {
+ std::env::set_var("DISPLAY", ":0");
+ std::env::remove_var("WAYLAND_DISPLAY");
+ }
+ assert!(has_graphical_display());
+
+ unsafe {
+ std::env::remove_var("DISPLAY");
+ std::env::set_var("WAYLAND_DISPLAY", "wayland-1");
+ }
+ assert!(has_graphical_display());
+
+ unsafe {
+ std::env::set_var("DISPLAY", " ");
+ std::env::remove_var("WAYLAND_DISPLAY");
+ }
+ assert!(!has_graphical_display());
+
+ unsafe {
+ if let Some(val) = orig_display {
+ std::env::set_var("DISPLAY", val);
+ } else {
+ std::env::remove_var("DISPLAY");
+ }
+ if let Some(val) = orig_wayland {
+ std::env::set_var("WAYLAND_DISPLAY", val);
+ } else {
+ std::env::remove_var("WAYLAND_DISPLAY");
+ }
+ }
+ }
}