MPV is a powerful media player that also works as a library. Rye can control it to play local files and internet streams, manage playlists, and read back playback information.
This package needs a build with -tags "b_contrib,b_mpv" and the libmpv library installed on your system (for example sudo apt install libmpv-dev on Debian/Ubuntu).
The player must be initialized before use. Options are set before Init, properties after.
; Create and initialize a player
player: mpv |Init
; Load and play a local file
player |Load "music.mp3"
player: mpv |Init
player |Load "music.mp3"
player |Pause
player |Play
player |Toggle-pause
; Volume (0-100), mute
player |Set-volume 80
player |Mute
player |Unmute
; Seek in seconds
player |Seek 30.0 ; forward 30 seconds
player |Seek -10.0 ; back 10 seconds
player |Seek\absolute 120.0 ; jump to 2:00
player: mpv |Init
player |Load "music.mp3"
; Wait a moment for playback to start
sleep 1000
print player .Position? ; seconds into the track
print player .Duration? ; total length
print player .Media-title? ; title or filename
print player .Paused? ; 1 if paused
print player .Volume?
Playback-status? returns a dict with position, duration, percent, cache-duration, paused, idle, and title all at once.
player: mpv |Init
player |Load "track1.mp3"
player |Load\append "track2.mp3"
player |Load\append "track3.mp3"
player |Playlist-next
player |Playlist-prev
player |Playlist-clear
Internet streams work the same way as local files. For audio-only streams you can disable video output.
player: mpv
|Set-option "vo" "null" ; no video output
|Set-option "vid" "no" ; disable video decoding
|Init
; Play a SomaFM stream
player |Load "https://somafm.com/groovesalad256.pls"
; Print the current track title in a loop
forever {
sleep 1000
title: player .Media-title? |fix { "Buffering..." }
print join { "Now playing: " title }
}
; Always terminate the player when finished
player |Terminate