08-22-2021, 11:35 AM
I could not find any mpd remote for phosh (some GTK desktop client do the job, but they're not appropriate to a mobile device), so here is a simple python file to perform basic actions (play, stop, pause, next, previous, enable/disable outputs). It relies on mpc to act with the server. One has to change the login string of the script with the right passwd and IP (let a space at the end). If you know about a real app that does the job, tell me. If you ever write one, i would try it . At home, the outputs i want to control are numbered 2 and 3 : change that according to your wishes…
#!/bin/python3
import gi, os
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
login="mpc -h your_password@ip_of_the_server "
class ButtonWindow(Gtk.Window):
def __init__(self):
super().__init__(title="MPD Remote")
self.set_border_width(10)
vbox = Gtk.VBox(spacing=6)
self.add(vbox)
button = Gtk.Button.new_with_label("Stop")
button.connect("clicked", self.on_stop_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Play")
button.connect("clicked", self.on_play_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Pause")
button.connect("clicked", self.on_pause_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Précédente")
button.connect("clicked", self.on_prec_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Suivante")
button.connect("clicked", self.on_suiv_clicked)
vbox.pack_start(button, True, True, 0)
switch = Gtk.Switch()
switch.connect("notify::active", self.on_switch_activated)
switch.set_active(True)
vbox.pack_start(switch, True, True, 0)
switch2 = Gtk.Switch()
switch2.connect("notify::active", self.on_switch2_activated)
switch2.set_active(True)
vbox.pack_start(switch2, True, True, 0)
def on_switch_activated(self, switch, gparam):
if switch.get_active():
state = "on"
os.system(login+"enable 3")
else:
state = "off"
os.system(login+"disable 3")
def on_switch2_activated(self, switch, gparam):
if switch.get_active():
state = "on"
os.system(login+"enable 2")
else:
state = "off"
os.system(login+"disable 2")
def on_stop_clicked(self, button):
os.system(login+"stop")
def on_play_clicked(self, button):
os.system(login+"play")
def on_pause_clicked(self, button):
os.system(login+"pause")
def on_suiv_clicked(self, button):
os.system(login+"next")
def on_prec_clicked(self, button):
os.system(login+"prev")
win = ButtonWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
#!/bin/python3
import gi, os
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
login="mpc -h your_password@ip_of_the_server "
class ButtonWindow(Gtk.Window):
def __init__(self):
super().__init__(title="MPD Remote")
self.set_border_width(10)
vbox = Gtk.VBox(spacing=6)
self.add(vbox)
button = Gtk.Button.new_with_label("Stop")
button.connect("clicked", self.on_stop_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Play")
button.connect("clicked", self.on_play_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Pause")
button.connect("clicked", self.on_pause_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Précédente")
button.connect("clicked", self.on_prec_clicked)
vbox.pack_start(button, True, True, 0)
button = Gtk.Button.new_with_mnemonic("Suivante")
button.connect("clicked", self.on_suiv_clicked)
vbox.pack_start(button, True, True, 0)
switch = Gtk.Switch()
switch.connect("notify::active", self.on_switch_activated)
switch.set_active(True)
vbox.pack_start(switch, True, True, 0)
switch2 = Gtk.Switch()
switch2.connect("notify::active", self.on_switch2_activated)
switch2.set_active(True)
vbox.pack_start(switch2, True, True, 0)
def on_switch_activated(self, switch, gparam):
if switch.get_active():
state = "on"
os.system(login+"enable 3")
else:
state = "off"
os.system(login+"disable 3")
def on_switch2_activated(self, switch, gparam):
if switch.get_active():
state = "on"
os.system(login+"enable 2")
else:
state = "off"
os.system(login+"disable 2")
def on_stop_clicked(self, button):
os.system(login+"stop")
def on_play_clicked(self, button):
os.system(login+"play")
def on_pause_clicked(self, button):
os.system(login+"pause")
def on_suiv_clicked(self, button):
os.system(login+"next")
def on_prec_clicked(self, button):
os.system(login+"prev")
win = ButtonWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()