Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix idle->playing state transition #90

Merged
merged 1 commit into from
May 5, 2023

Conversation

pritambaral
Copy link
Contributor

@pritambaral pritambaral commented Apr 28, 2023

The Bug

When mpv is started with the --idle=yes CLI flag, MPV_EVENT_IDLE fires almost immediately at process start. This causes mpv-mpris to mark PlaybackStatus as STOPPED.

When a file/URL is subsequently loaded into mpv and starts playing, mpv-mpris continues to believe that playback is stopped.

Steps to Repro

  1. Start mpv in idle mode, either with an IPC server (e.g., --input-ipc-server=/tmp/mpv.sock) or in Pseudo GUI mode (--player-operation-mode=pseudo-gui).
  2. Check MPRIS status, it should have an player entry for this mpv instance but without any media playing in it.
  3. Load a file/URL into the idle mpv instance — either via the loadfile IPC command if in IPC mode or via drag-and-drop if in Pseudo GUI mode — and wait until mpv starts playing it
  4. Check MPRIS status.
    Expected: The mpv instance has the selected media playing, the seek status is being continuously updated, and MPRIS controls to pause and play work.
    Actual: The mpv instance has the selected media playing, but the seek status does not update, and MPRIS controls to pause and play do not work.

The Fix

Turns out, MPV_EVENT_IDLE was designed only for a state transition into idle state, and is itself deprecated, with the "idle-active" property suggested as a proper substitute. This property changes correctly both when entering as well as exiting idle state.

The Workaround

Curiously, the "pause" property starts out as false in --idle=yes mode, thus playback start never triggers a property change for it, and thus mpv-mpris remains in a stopped state. This temporary incorrectness in state is automatically corrected, however, when playback is subsequently paused.

@hoyon
Copy link
Owner

hoyon commented Apr 29, 2023

Hi @pritambaral, thanks for the PR! Your explanation makes sense but sadly it seems to have broken the tests. Are you able to take a look at what's gone wrong?

When mpv is started with the `--idle=yes` CLI flag, MPV_EVENT_IDLE fires
almost immediately at process start. This causes mpv-mpris to mark
`PlaybackStatus` as `STOPPED`.

When a file/URL is subsequently loaded into mpv and starts playing,
mpv-mpris continues to believe that playback is stopped.

Turns out, MPV_EVENT_IDLE was designed only for a state transition into
idle state, and is itself deprecated, with the "idle-active" property
suggested as a proper substitute. This property changes correctly both
when entering as well as exiting idle state.

Curiously, the "pause" property starts out as false in `--idle=yes`
mode, thus playback start never triggers a property change for it, and
thus mpv-mpris remains in a stopped state. This temporary incorrectness
in state is automatically corrected, however, when playback is
subsequently paused.
@pritambaral
Copy link
Contributor Author

Hi @pritambaral, thanks for the PR! Your explanation makes sense but sadly it seems to have broken the tests. Are you able to take a look at what's gone wrong?

Fixed, @hoyon. I pulled idle state tracking out of paused state tracking, since mpv tracks them as separate states anyway. The two states are merged into a single "PlaybackStatus" when reporting to MPRIS; except in an MPV_EVENT_SHUTDOWN, since I expect that to be followed only by a process exit and no further changes to idle or paused states.

@hoyon hoyon merged commit a96a6ed into hoyon:master May 5, 2023
1 check passed
@hoyon
Copy link
Owner

hoyon commented May 5, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants