0

This python program shall play a playlist from Mediapplayer. When one song ends or after typing on the keyboard the playlist will play the next song.

The input is:

#!/usr/bin/python
#-*-coding:ascii-*-

import dbus
import gobject

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()

banshee = bus.get_object('org.mpris.MediaPlayer2.banshee',
               '/org/mpris/MediaPlayer2')
iface = dbus.Interface(banshee,'org.mpris.MediaPlayer2.Player')

loop = gobject.MainLoop()
def on_reply():
        print"Start"
def on_error():
        print"Error"
def next_song():
        print"Next Song"
        iface.Next(reply_handler=on_reply,
        error_handler=on_error)
        gobject.timeout_add(4,next_song)
def on_error(error):
        print"Error"
        loop.quit()
        next_song()
try:
        loop.run()
finally:
        print"End"
        iface.Stop() 

The output: Nothing

Thank you in advance

Studie
  • 799
  • 2
  • 12
  • 20

3 Answers3

1

mdbus2 should give a list of available methods. Taken from this page:

$ mdbus2 org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2
...
[METHOD]    org.mpris.MediaPlayer2.Player.Pause() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.PlayPause() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Stop() -> ()
[METHOD]    org.mpris.MediaPlayer2.Player.Play() -> ()
...

Adjust the example to reflect the fact that you're interfacing with Banshee. I tried installing Banshee and mdbus2 to try this out myself, but the installer script failed.

You can also try using Python's built-in tools for introspection.

$ python
>>> from org.mpris.MediaPlayer2 import Player
>>> dir(Player)

Even better, drop a similar statement in your program. Your body of code is currently trivial enough that you can just print out the result of dir().

finally:
    print"End"
    dir(iface)
    iface.Stop()
Ichimonji10
  • 344
  • 1
  • 3
  • 9
  • thanks a lot, but the error is in line iface.Stop() The error-print tells that Stop() is a unknown method and that the interface "org.mpris.MediaPlayer2.Player" doesn't exist – Studie Aug 29 '12 at 05:33
1

You can use d-feet to see if the method is available on the interface you are trying to use.

You can also use dbus-monitor to see what messages are passed on the bus. The syntax should be like this:

dbus-monitor --monitor --address <your_bus_address>

You will get all the messages on the bus with the command above. To filter, you can do something like:

dbus-monitor --monitor --address <your_bus_address> interface=<IF_name> path=<path_name> dest=...

You cannot use partial interface/path names in filtering. You can always grep for some advanced filtering.

You usually get this error if either the method is not available on that interface, or you try to call it with a wrong set of parameter types. Check the function signature also, in your calling code.

Alexandru C.
  • 3,337
  • 1
  • 25
  • 27
  • By default it prints everything that is going on on the bus. You can filter the messages. I have edited the message to show how to filter. You should filter using the interface you are interested in. – Alexandru C. Aug 29 '12 at 08:31
  • This is the print: signal sender=org.freedesktop.DBus -> dest=:1.166 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired string ":1.166" – Studie Aug 29 '12 at 09:17
  • Yes, these are the messages shown when dbus-monitor registers itself on the bus. If you leave it running and then start calling methods, sending signals on the bus, from your application, you will see the messages as they will be printed on dbus-monitor. – Alexandru C. Aug 29 '12 at 09:40
  • I have updated my Question. I found little mistakes. Now the programm is running without any print. So I have to end this process by myself with the command "ctr + Z" – Studie Aug 29 '12 at 13:07
1

The path was wrong. The correct path is:

banshee = bus.get_object("org.bansheeproject.Banshee", "/org/bansheeproject/Banshee/PlayerEngine")

On the following page you get more informations about the path and how it works.

Studie
  • 799
  • 2
  • 12
  • 20