termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

implement MPRIS

Open nonetrix opened this issue 3 years ago • 1 comments

Feature description If a program uses MPRIS it should come up as a media player in the notification shade so it can be paused or played etc like such

KOg-Ycw7yqUxMAxxI9QbaStIxTZiDUAurc7Qi9XM6o0

This would be much more convenient than having to unlock my phone and then pausing the music or skipping etc

Reference implementation https://specifications.freedesktop.org/mpris-spec/latest/

Have you checked if the feature is accessible through the Android API? Yes https://developer.android.com/guide/topics/media/media-controls Do you know of other open-source apps that has a similar feature as the one you want? (Provide links) https://github.com/RetroMusicPlayer/RetroMusicPlayer

nonetrix avatar Jul 05 '22 20:07 nonetrix

It doesn't have thumbnails or time control, but here's a (hacky) script I made that lets you control an MPRIS app from a termux-api notification:

#!/bin/bash

# get dbus-launch env variables
dbvars=$(dbus-launch)
echo using dbus-launch output: $dbvars

makecmd() (
	echo -n export $dbvars\; dbus-send --print-reply --dest=
	echo -n '$(dbus-send --session --dest=org.freedesktop.DBus --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | fgrep org.mpris.MediaPlayer2. | head -1 | awk '"'"'{print $2}'"'"' | sed '"'"'s:"::g'"'"')'
	echo -n ' '
	echo /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$1

	# termux-notification --type media 
)

makenotif() (
	playcmd=$(eval makecmd "Play")
	ppcmd=$(eval makecmd "PlayPause")
	prevcmd=$(eval makecmd "Previous")
	nextcmd=$(eval makecmd "Next")
	pausecmd=$(eval makecmd "Pause")
	termux-notification --type media --id 1096 --priority max --title "termux-media-controls" --media-next "$nextcmd" --media-previous "$prevcmd" --media-pause "$ppcmd" --media-play "$ppcmd"
)
makenotif

echo "Subshell started. If you run an MPRIS-supporting player here, you'll be able to control it with the notification that was just shown"
export $dbvars
exec bash

Just save it somewhere and run it with no arguments.

redcathode avatar Jul 12 '22 13:07 redcathode