This is my mpv wrapper script. It takes a url as an argument or from the copy buffer and attempts to play it in mpv. If mpv can't play the url, a notification is used to let you know it failed. This is important if the script is executed via a keybinding or launched from another application.
Here are various configurations I use with this script. Wayland users might need to set XDG_SESSION_TYPE=wayland
environment variable.
bindsym $mod+m exec "/path/to/mpv-wrapper.sh"
[summary=mpv]
background-color=#520053
[mpv]
summary = "mpv"
background = "#520053"
config.bind('M', 'hint links spawn /path/to/mpv-wrapper.sh {hint-url}')
video/*; /path/to/mpv-wrapper.sh '%s' ; test=test -n "$DISPLAY"
Way back when, I used a Firefox extension to launch audio/video links in mpv until Firefox removed that functionality. This script was a work around that I came up with and it has evolved over time.