noctalia-shell icon indicating copy to clipboard operation
noctalia-shell copied to clipboard

[BUG] V5: media control is not working after logon

Open jenningsloy318 opened this issue 5 months ago • 4 comments

Submission checklist

  • [x] I have searched existing issues and confirmed this is not a duplicate.
  • [x] I am using the latest available version of Noctalia.

Bug description

Summary

Noctalia evicts an MPRIS player from its cache the moment it sees a metadata snapshot without xesam:title / xesam:artist / xesam:album, and then never re-introspects it unless the bus name owner changes. Players that come up in Stopped state with placeholder-only metadata (a perfectly valid MPRIS state) are therefore permanently invisible to the bar's media widget and to noctalia msg media …, even after they later start playing real tracks with full metadata.

I hit this with termusic-server 0.13.2 launched at session start, but the gating logic is generic — any compliant player whose first PropertiesChanged carries placeholder-only metadata will be evicted.

Workaround that confirms the diagnosis: change the autostart line to nudge termusic into Playing once so it emits a strong-metadata snapshot before noctalia introspects:

  exec_always sh -c 'pkill -x termusic-server; sleep 1; setsid -f termusic-server; sleep 4; \
    playerctl --player=termusic play; sleep 1; playerctl --player=termusic pause'

With this, players_cached=1 and everything works for the rest of the session. Without it, the cache is permanently empty.

Root cause (in source) src/dbus/mpris/mpris_service.cpp HEAD (512ecc89):

Strength predicate — lines 210-215:

  bool hasStrongNowPlayingMetadata(const MprisPlayerInfo& info) {
    // Track IDs/source URLs can exist during transient "loading" states where the
    // user-visible metadata is still placeholder-only (e.g. app identity + logo).
    // Treat metadata as strong only when actual now-playing fields are present.
    return !info.title.empty() || !info.artists.empty() || !info.album.empty();
  }

Eviction without retry — lines 1717-1722 (inside the org.freedesktop.DBus.Properties.GetAll callback that runs after a NameOwnerChanged):

  const MprisPlayerInfo info =
      readPlayerInfoFromProperties(busName, effectiveRootProps, effectivePlayerProps);
  if (!playerFailed && !hasStrongNowPlayingMetadata(info)) {
    removePlayerCacheEntry(busName);
    return;
  }
  applyPlayerSnapshot(busName, info, hadPositionSignal, hadFullRefreshFailure);

Re-discovery trigger — lines 1420-1427:

  m_dbusProxy->uponSignal("NameOwnerChanged")
      ...
      kLog.debug("name owner changed name={} old_owner=\"{}\" new_owner=\"{}\"", name, old_owner, new_owner);

The pipeline is: NameOwnerChanged arrives → fetch properties → if metadata is placeholder, evict and return → no further trigger refills the cache. PropertiesChanged signals on the already-evicted bus name don't re-introspect because the bus name was never "removed" in DBus terms; the same owner is still there, just no longer cached on noctalia's side. The eviction is permanent for the lifetime of that bus name owner.

When termusic-server is first spawned and is in Stopped state (per startup_state = "paused" followed by no track loaded yet), its org.mpris.MediaPlayer2.Player.Metadata property is exactly: { "mpris:trackid": ObjectPath("/") } — no xesam:title, xesam:artist, or xesam:album. This is a valid MPRIS 2 state for a player that has nothing loaded, and the spec doesn't require those fields. hasStrongNowPlayingMetadata() returns false, noctalia evicts, and never comes back.

Steps to reproduce

  1. Configure termusic to autostart at session login with startup_state = "paused". Compositor autostart line:
  exec_always sh -c 'pkill -x termusic-server; sleep 1; setsid -f termusic-server'
  2. Log into the noctalia session.
  3. Open the bar's media widget — shows Nothing playing.
  4. Run any playback control: noctalia msg media toggle. No effect.
  5. Manually start a track from the termusic TUI. Bar still says Nothing playing. Real org.mpris.MediaPlayer2.termusic PropertiesChanged signals with full
  xesam:title/artist/album are flowing on the bus (verified with busctl --user monitor).
  6. Tail noctalia log:
  tail -f ~/.cache/noctalia/noctalia.log | grep mpris
  6. Repro shows:
  [mpris] name owner changed name=org.mpris.MediaPlayer2.termusic old="" new=:1.NNN
  [mpris] manual player refresh requested players_cached=0
  6. players_cached stays at 0 forever after the initial eviction.

Expected behavior

we can control the media when login into noctalia, no need to start termusic tui again while the termusic-server is already started

Actual behavior

click the media widget control play button, nothing happend

Logs / error output

Logs / supporting data

  - ~/.cache/noctalia/noctalia.log extract showing players_cached=0 permanence — happy to attach a sanitized full session log on request.
  - busctl --user introspect org.mpris.MediaPlayer2.termusic /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player confirming a fully MPRIS-compliant
  interface.
  - playerctl --player=termusic status returns Stopped then Playing correctly throughout — the player itself is fine.

Noctalia version

noctalia v5.0.0 (65b228b95022)

Compositor

Sway

Distribution

Debian-based

Environment information

- noctalia-shell: 512ecc899964314a251aca4be279a66f875803e5 (master, git pull performed before filing)
  - OS: Debian GNU/Linux 13 (trixie), x86_64
  - Compositor: sway 1.10 (also reproduced under niri)
  - Reporting player: termusic-server v0.13.2-46-gb4347f18 with use_mediacontrols = true, startup_state = "paused"

Additional context

No response

jenningsloy318 avatar Jun 09 '26 13:06 jenningsloy318

Thanks for the report. I checked the current MPRIS code and the proposed root cause does not look correct: removePlayerCacheEntry() clears the visible player cache, but it does not remove the D-Bus proxy or the PropertiesChanged signal handler, so later metadata changes should still call addOrRefreshPlayer() for the same bus name.

The issue may be that a stopped/no-track player is not kept as an active controllable player, so noctalia msg media toggle has nothing to target at login. Could you attach logs showing whether Noctalia receives the later PropertiesChanged signal with full metadata, and whether the follow-up property refresh succeeds or fails?

ItsLemmy avatar Jun 11 '26 21:06 ItsLemmy

Stale

ItsLemmy avatar Jun 16 '26 00:06 ItsLemmy

Hi @ItsLemmy — sorry, didn't get a chance to attach the requested data before the stale close. The diagnosis still reproduces on master; please consider reopening. Here's the evidence you asked for.

  1. termusic does emit live PropertiesChanged on the Player interface

dbus-monitor capture, current session, no patches, stock upstream termusic 0.13.2, player has never been touched after autostart:

  signal sender=:1.85 -> destination=(null destination) path=/org/mpris/MediaPlayer2;
    interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
     string "org.mpris.MediaPlayer2.Player"
     array [
        dict entry( string "PlaybackStatus"  variant string "Paused" )
     ]
     array [ ]

These fire every 500 ms (termusic's tick loop). Path, interface, body — all valid MPRIS 2. Noctalia is on the bus during this window. If addOrRefreshPlayer() re-ran on these, the bar would populate; it doesn't.

  1. The player is Paused, not Stopped, and is fully controllable
  dbus-send … GetAll org.mpris.MediaPlayer2.Player:

  PlaybackStatus = "Paused"
  CanPlay        = true
  CanControl     = true
  CanGoNext      = true
  CanPause       = true
  Metadata       = { "mpris:trackid": ObjectPath("/") }

So the "stopped/no-track player not kept as controllable" line of reasoning doesn't apply here — the player is Paused with CanPlay=CanControl=true. The only thing "missing" is xesam:title/artist/album, which the MPRIS-2 spec explicitly allows to be absent (only mpris:trackid is required for a player that has a track concept at all, and even that isn't strictly required when nothing is loaded).

  1. Cross-confirmation from the player's upstream

I filed tramhao/termusic#716 to publish strong metadata at startup. Collaborator hasezoey responded:

▎ "I was not aware that some MPRIS displays just evict Stopped players or "first-publish-empty-metadata", that looks to be a ▎ implementation problem on their side."

So both sides of the bus agree the gating belongs in noctalia, not in every conformant player.

  1. Workaround keeps confirming the diagnosis
  exec_always sh -c 'pkill -x termusic-server; sleep 1; setsid -f termusic-server; sleep 4;
    playerctl --player=termusic play; sleep 1; playerctl --player=termusic pause'

After this one-shot nudge, players_cached=1 and stays that way for the whole session. The only thing the nudge changes is that the first GetAll reads strong metadata. Every subsequent PropertiesChanged for that session looks identical to the no-nudge case — i.e. the eviction is sticky per–bus-name-owner.

Suggested fix shape (for discussion)

Either of these would resolve it without dropping the strong-metadata check elsewhere:

  1. In the NameOwnerChanged → GetAll callback, don't return after removePlayerCacheEntry(busName) — keep the proxy/handlers and let the next PropertiesChanged re-trigger addOrRefreshPlayer(). Alternatively register a one-shot retry timer.
  2. Loosen hasStrongNowPlayingMetadata() to accept a player with CanControl=true even if title/artist/album are empty — it's still a valid controllable player per spec.

jenningsloy318 avatar Jun 23 '26 12:06 jenningsloy318

@jenningsloy318 Hello, do you the issue on the latest 5.3 version? Can you check and report. Thanks

AdityaKr015 avatar Oct 17 '26 06:10 AdityaKr015