Skip to content

Stop playback glitch when clearing mediaList while a media player is attached #39

Description

@omaralbeik

Summary
Setting mediaList = nil while a media player is attached can stop active playback that the rebuilt list player is supposed to keep running.

Location: Sources/SwiftVLC/Playlist/MediaListPlayer.swift:187-207

Details
rebuildNativePlayer binds the same native media player to the new list player, then offloads stop + release of the old one without detaching that shared media player first:

if let mediaPlayer = _mediaPlayer {
  libvlc_media_list_player_set_media_player(replacement, mediaPlayer.pointer)
}
...
DispatchQueue.global(qos: .utility).async {
  libvlc_media_list_player_stop_async(oldPointer)
  libvlc_media_list_player_release(oldPointer)
}

libvlc_media_list_player_stop_async calls vlc_player_Stop on the underlying media player (media_player.c), and that player is shared with the replacement. So the old handle stops the very player the rebuilt list player just adopted. Reachability: the mediaList = nil setter calls rebuildNativePlayer with _mediaPlayer still set (set mediaPlayer first, then clear mediaList). Refcounting prevents a use-after-free, so the impact is a playback glitch, not a crash.

Suggested fix
When the media player is shared with the replacement, do not call stop_async on the old handle. Detach the old list player's media list (libvlc_media_list_player_set_media_list(old, nil) is not allowed since libVLC asserts non-null, so just skip the stop) and only release it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions