basic and ugly mpc-python-GTK3 mpd remote
#1
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 Wink. 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()
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How-To: Remote Control Your Phone from Desktop via VNC biketool 2 419 10-12-2024, 11:47 AM
Last Post: biketool
  Accessing the camera from Python lagrang3 8 3,489 07-25-2023, 07:42 PM
Last Post: Kevin Kofler
  Remote connection from Linux Mobile to unrooted Android? (surely very useful?!) 4w7gvrvsjcyvd 0 2,073 01-30-2021, 06:48 PM
Last Post: 4w7gvrvsjcyvd
  Is there a sound card input on the Pinephone which can be used by Python software? Peter Gamma 5 7,747 06-24-2020, 06:08 AM
Last Post: wibble

Forum Jump:


Users browsing this thread: 1 Guest(s)