Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writing bytes to omxplayer's OutputStream from java #116

Closed
jimpil opened this issue Dec 17, 2013 · 40 comments
Closed

writing bytes to omxplayer's OutputStream from java #116

jimpil opened this issue Dec 17, 2013 · 40 comments

Comments

@jimpil
Copy link

jimpil commented Dec 17, 2013

Hello everyone,

First of all I should clarify that this is probably not an issue with omxplayer...it seems that some people have managed to spawn and control an omxplayer Process from Java code but I can't find any working code anywhere! Now that oracle-java-7 is in the official repos, I've written a rudimentary playlist GUI for the pi.

I can successfully spawn the omxplayer process but there is no way to control it from my code...The Process runs until the video/song finishes and then it starts over!!! Only option is to reboot...I've literally tried everything and I am following all the best practices (buffered streams and ProcessBuilder). Here is the code snippet that should write the bytes for quitting omxplayer (q char):

if (p != null){ //p is the Process object return by ProcessBuilder.start()
BufferedOutputStream stdin = new BufferedOutputStream(p.getOutputStream()); 
String x = "q";
stdin.write(x.getBytes());
stdin.flush();
}

However ,the above code pattern does not work for anything (volume, pausing, quitting etc). I 've even tried putting the code that starts the Process in a separate thread and still nothing.

I do realise that this is not the most appropriate place to ask for help but I am slightly desperate! I cannot think of anything else to try out...To my surprise, p.destroy() doesn't work either!!! Any help/pointers are greatly appreciated...

many thanks in advance,
Jim

@popcornmix
Copy link
Owner

Have you looked into using the dbus interface (from java) to control omxplayer?
It was implemented for exactly the purpose of and external app controlling omxplayer.

@jimpil
Copy link
Author

jimpil commented Dec 17, 2013

Wow! quick reply...many many thanks!

No, I haven't looked at dbus...Would you happen to have any links handy?

@popcornmix
Copy link
Owner

Well, you want to implement code similar to:
https://github.com/popcornmix/omxplayer/blob/master/Keyboard.cpp
from your java program. It should do the dbus connect and then send commands.

There appears to be a dbus-java package which may be helpful.

@jimpil
Copy link
Author

jimpil commented Dec 17, 2013

I am at a complete loss here...After many hours I managed to install dbus-java and also found this: http://code.google.com/p/rocksources/wiki/OMXPlayerDbus which I managed to install on the Pi. However, trying to do 'CreateInterface' as described here : http://wiki.apertium.org/wiki/Compiling_a_Java_D-Bus_program , fails. All I changed is the interface name:

CreateInterface raspberry.pi.OMXPlayer     / > pi/OMXDBUSPLAYER.java
CreateInterface raspberry.pi.OMXPlayerList / > pi/OMXDBUSPLAYLIST.java
ERROR: Failure in DBus communications: The name raspberry.pi.OMXPlayer was not provided by any .service files.

Do I need to somehow start the omxplayer-dbus service?

@popcornmix
Copy link
Owner

Does omxplayer run for you and have working keyboard?

You'll need something like the current omxplayer wrapper which starts a dbus daemon:
https://github.com/popcornmix/omxplayer/blob/master/omxplayer#L50

@jimpil
Copy link
Author

jimpil commented Dec 17, 2013

Does omxplayer run for you and have working keyboard?

From the command-line it runs and responds to keystrokes just fine. From my Java application it starts but doesn't respond to keystrokes. I am currently trying to adapt my code so that it uses the dbus service but inorder to do that I need to generate some Interfaces, namely the raspberry.pi.OMXPlayer and raspberry.pi.OMXPlayerList, before I can even compile...

You'll need something like the current omxplayer wrapper which starts a dbus daemon

I think have the latest build of omxplayer [9b52cee] because it updated a week or so ago. When exactly does it start the deamon? When omxplayer starts or when the pi boots up?

I cannot express how grateful I am for taking the time to reply to me even if the issue is not resolved...many thanks :)

@jimpil
Copy link
Author

jimpil commented Dec 18, 2013

Ok I think I've made some progress...I checked my omxplayer wrapper script and it does indeed start the dbus-deamon. I am not sure it closes it (ps xaf shows many instances) after playback but at least it starts it. So, it follows that I should be able to do the following while omxplayer is running, in order to generate the interfaces I need.

CreateInterface raspberry.pi.OMXPlayer  -s -f   /raspberry/pi/OMXDBUSPLAYER.java

However this still fails with the same message: "the name raspberry.pi.OMXPlayer was not provided by any .service files". The same for raspberry.pi.OMXPlayerList.

The other alternative is to somehow find the 'introspection.xml' for omxplayer and generate the interfaces from there. The funny thing is that if I knew the right name I could generate the xml automatically, while the process is running! But I know neither the right name, nor I can find the introspection.xml... if you can provide either of these (dbus service name or introspection.xml), it should be straight forward to generate the interfaces and I can finally start to write the controlling code.

thanks in advance

@popcornmix
Copy link
Owner

I'd guess this is the dbus name:
https://github.com/popcornmix/omxplayer/blob/master/OMXControl.h#L1

@jimpil
Copy link
Author

jimpil commented Dec 18, 2013

It is not unfortunately...Moreover, DBusViewer shows a bunch of processes but none related with omxplayer, even though omxplayer is streaming radio in the background! Screenshot can be found here: https://dl.dropboxusercontent.com/u/45723414/2013-12-18-184028_1280x720_scrot.png

would it perhaps be easy for you to install dbus-java on your pi and then type DBusViewer in a terminal, while omxplayer is playing something? Can you find the omx dbus process under 'SESSION'?

I can't remember when it was the last time I struggled so much to generate an interface....

@fcarlier
Copy link

You must listen the good 'DBUS_SESSION_BUS_ADDRESS' and dbus name.

omxplayer + Java on RaspBerry ;(

2 Terminal = 2 sessions

@jimpil
Copy link
Author

jimpil commented Dec 19, 2013

Hi fcarlier,

I'm not sure what you mean...could you elaborate a bit further? do you happen to know what dbus-process to listen to?

@jimpil
Copy link
Author

jimpil commented Dec 19, 2013

I installed mdbus2 on my pi but doing mdbus2 | grep omxplayer returns nothing! Doing mdbus2 | grep vlc returns: org.mpris.MediaPlayer2.vlc
org.mpris.MediaPlayer2.vlc-2960
as you would expect...

guys, what on earth is happening? should I just give up?

@subogero
Copy link

I can confirm that omxplayer ignores control characters from STDIN, when it's coming from a pipe. See #131.

@jehutting
Copy link

Hi @jimpil

I installed mdbus2 on my raspberry pi. Executing it shows

org.freedesktop.DBus
org.mpris.MediaPlayer2.omxplayer

Of course you only see the second line when omxplayer is running ;)

Also notice that mdbus2 without any argument looks default to the SESSION bus. Initial implementations of omxplayer ran on the SYSTEM bus. Nowadays omxplayer is running on the session bus. So I assume that you are up-to-date.

You looked at the 'rocksources' OMXPlayerDbus implementation. Although that code (interface) seems fine, it isn't the one omxplayer uses. Omxplayer D-Bus interface implements the "MPRIS D-Bus Interface Specification" (MEDIAPLAYER2) interface. So you should use the OMXPLAYER_DBUS_xxx values which are defined in omxplayer's OMXControl.h.

BUT when I say omxplayer I refer to POPCORNMIX omxplayer. Are you using this one? Because you talk about raspberry.pi.OMXPlayerList. At this moment omxplayer doesn't have playlist support, and that interface name is definitly wrong/unknown to omxplayer. 'rocksources' omxplayer on the otherhand has this interface, so are you using that omxplayer code? Maybe that would explain why you get confused by above comments ;)

I glanced through the 'rocksources'; it uses the SYSTEM bus.

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

Hi @jehutting,

First of all thank you for taking the time to investigate. What you say makes sense and that is actually what I tried to do. You are right that initially I got confused by the 'rocksources' dbus interface, but later on I realised that I need to implement a different interface, namely the org.mpris.MediaPlayer2.omxplayer.

Now I have a couple of questions...you say that 'executing mdbus2 while omxplayer is running'...how exactly are you doing this? On my pi, if I open a separate terminal than the one omxplayer is using, and type 'mdbus2', I get nothing back, presumably because it is a different SESSION. But there is no way to run omxplayer and the mdbus2 command in the same terminal, is there? Ultimately, I want to generate the Java interface. In order to do that I need either the XML file containing the introspection data, or by querying the remote object over D-Bus, via 'CreateInterface'. My problem is that I cannot find the remote object...Once I generate the Java interface, I literally need nothing else in order to write a rudimentary playlist for omxplayer...

Any suggestions?

@jehutting
Copy link

Hi @jimpil,

Just like you do, I open an ssh connection to my raspberry pi, and run omxplayer within it. Then I start a second ssh connection and execute mdbus2 in it. It shows the "org.mpris.MediaPlayer2.omxplayer" in its output.

I would expect that you should at least see 'org.freedesktop.DBus'.

I run omxplayer.bin directly, so not using the omxplayer script. I'm not able to run that script, so I can't check if this makes the difference. Are you running direct or through the script? If through the script, maybe you can try it out if a direct run makes the difference.

I'm also curious what a "ps xaf | grep -i dbus" gives as output (on the second ssh terminal).

$ ps xaf | grep -i dbus
 2204 ?        Ss     0:00 /usr/bin/dbus-daemon --system
 2688 pts/1    S+     0:00              \_ grep --color=auto -i dbus
 2624 pts/0    S      0:00 dbus-launch --autolaunch 355ec9f99dfe1d2519ffc50d508db147 --binary-syntax --close-stderr
 2625 ?        Ss     0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session

As you can see I have only ONE dbus-daemon (and don't get multiple ones). The one and only is started up as a result of omxplayer running. It isn't killed after omxplayer ends playing, but that is another issue ?-)
If you are able to run the script, I would like to see if there are multiple daemons active. Maybe having more than one daemon active, omxplayer has trouble making a DBus connection. I'm just guessing.

If you don't get a dbus-daemon, it tells me that your omxplayer is not using/running a D-Bus connection. In one of your above comment, you checked that you were able to control omxplayer by keyboard. Is that still the case? Does it pause when you hit e.g. the 'p'-key? I now assume you are running the POPCORNMIX omxplayer?

I'm not a Java expert and don't know about the 'CreateInterface' stuff. It is also unknown on my RPI. I could install the java package and give it a try to see what kind of output I get. But probably that still won't give you the ability to use it yourself.

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

On 18/01/14 13:34, Jozef Hutting wrote:

Hi @jimpil https://github.com/jimpil,

Just like you do, I open an ssh connection to my raspberry pi, and run
omxplayer within it. Then I start a second ssh connection and execute
mdbus2 in it. It shows the "org.mpris.MediaPlayer2.omxplayer" in its
output.

I would expect that you should at least see 'org.freedesktop.DBus'.

I run omxplayer.bin /directly/, so not using the omxplayer /script/.
I'm not able to run that script, so I can't check if this makes the
difference. Are you running direct or through the script? If through
the script, maybe you can try it out if a direct run makes the difference.

I'm also curious what a "ps xaf | grep -i dbus" gives as output (on
the second ssh terminal).

|$ ps xaf | grep -i dbus
2204 ? Ss 0:00 /usr/bin/dbus-daemon --system
2688 pts/1 S+ 0:00 _ grep --color=auto -i dbus
2624 pts/0 S 0:00 dbus-launch --autolaunch 355ec9f99dfe1d2519ffc50d508db147 --binary-syntax --close-stderr
2625 ? Ss 0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
|

As you can see I have only ONE dbus-daemon (and don't get multiple
ones). The one and only is started up as a result of omxplayer
running. It isn't killed after omxplayer ends playing, but that is
another issue ?-)
If you are able to run the script, I would like to see if there are
multiple daemons active. Maybe having more than one daemon active,
omxplayer has trouble making a DBus connection. I'm just guessing.

If you don't get a dbus-daemon, it tells me that your omxplayer is not
using/running a D-Bus connection. In one of your above comment, you
checked that you were able to control omxplayer by keyboard. Is that
still the case? Does it pause when you hit e.g. the 'p'-key? I now
assume you are running the POPCORNMIX omxplayer?

I'm not a Java expert and don't know about the 'CreateInterface'
stuff. It is also unknown on my RPI. I could install the java package
and give it a try to see what kind of output I get. But probably that
still won't give /you/ the ability to use it yourself.


Reply to this email directly or view it on GitHub
#116 (comment).

If you don't mind can you try the following? Install java-dbus on your
rpi (it is in the repos) and try this while omxplayer is running:

CreateInterface --session --create-files org.mpris.MediaPlayer2.omxplayer

Does it create the interface I need, in the correct hierarchy?

Jim

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

On 18/01/14 13:34, Jozef Hutting wrote:

Just like you do, I open an ssh connection to my raspberry pi, and run
omxplayer within it. Then I start a second ssh connection and execute
mdbus2 in it. It shows the "org.mpris.MediaPlayer2.omxplayer" in its
output.

I would expect that you should at least see 'org.freedesktop.DBus'.

When I do exactly what you describe I get:

Can't hook to DBus session bus: Command line `dbus-launch
--autolaunch=c76f6c7332c486d041b6528b51a0ef02 --binary-syntax
--close-stderr' exited with non-zero exit status 1: Autolaunch error:
X11 initialization failed.\n

apparently it needs an X window running!!!

It seems to me that the only way to run mdbus2 is from within X where
each terminal belongs to a separate SESSION!!!

How did you run mdbus2 from ssh???

Jim

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

from within X, mdbus2 gives me:

org.freedesktop.DBus
org.gtk.private.AcfVolumeMonitor
org.gtk.private.GPhoto2VolumeMonitor
org.gtk.private.GduVolumeMonitor
org.gtk.vfs.Daemon

I assume that everything is fine...the problem is how to run mdbus2 and omxplayer in the same session.
ssh gives me a login-shell where mdbus2 fails.

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

Regarding your questions on a previous message, I am pretty sure I am using POPCORNMIX omxplayer as I installed it through the official raspbian repos. I am also guessing it is up to date as I update regularly...in fact I remember it was recently updated (start of December if I am not mistaken). Also the keys work just fine from ssh. I am launching omxplayer, via the omxplayer command which became available after install. So I am guessing that I am calling the executable directly as well, just like you do.

@jehutting
Copy link

Oops...I see I forgot a little small but very important detail. Sorry for that!

You MUST use the -X (capital X) option of ssh. This does X11 forwarding and sets some environment settings correct for the terminal (/shell/session). One of them is DISPLAY. Without a correct value you get your problem.

So WITHOUT the -X you get

$ mdbus2
Can't hook to DBus session bus: Command line `dbus-launch --autolaunch=355ec9f99dfe1d2519ffc50d508db147 --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
$ echo $DISPLAY
<empty line>

and WITH the -X you get the mdbus2 output and something like

$ echo $DISPLAY
localhost:11.0

I don't run the GUI (X11 windows) on my RPI. Just from the plain command line (CLI) through ssh. I will start the X Windows and see if there is any difference between GUI and CLI behavior.

I can install java-dbus for you. But is there anything that I need further more to see if that is working. Any specific java tool?

But I am still curious what a "ps xaf | grep -i dbus" says. From plain CLI and now also from GUI if possible.

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

Right ok we are getting somewhere...so you are right. using the -X switch it works. However, it only reports org.freedesktop.DBus, even though omxplayer is running! I guess this is a major problem...Now, on the terminal where I typed mdbus2, I typed "ps xaf | grep -i dbus" and this is what I got:

pi@raspberrypi ~ $ ps xaf | grep -i dbus
 2153 ?        Ss     0:00 /usr/bin/dbus-daemon --system
 2449 pts/1    S+     0:00              \_ grep --color=auto -i dbus
 2381 ?        Ss     0:00 dbus-daemon --fork --print-address 5 --print-pid 6 --session
 2440 pts/1    S      0:00 dbus-launch --autolaunch=c76f6c7332c486d041b6528b51a0ef02 --binary-syntax --close-stderr
 2441 ?        Ss     0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session

I am not sure what to make of this though... :(

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

From what I remember you don't need anything else to try out yourself. Just sudo apt-get java-dbus and then try the CreateInterface command as shown before, while omxplayer is running. If you manage to get the files back (the interfaces in the right directory sctructure), that would be simply awsome cos you can then simply send them to me...the question then is "why doesn't mdbus2 show omxplayer in my rpi?"

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

this is the exact command:
CreateInterface --session --create-files org.mpris.MediaPlayer2.omxplayer

maybe you can omit the --session bit

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

I am sorry I did not remember correctly! The package is called dbus-java-bin ... apologies.

@jehutting
Copy link

OK. Great!

What I make of the ps output is

  • that the first dbus-daemon with (--print-pid 6) comes from the omxplayer script in which it is forked, and
  • that the second one is the one (and ONLY) I see!

Remember that I'm running omxplayer.bin, so without the script that I'm unable to run. So the forked dbus-daemon is the only difference here!? Can't imagine mdbus2 has trouble with multiple dbus-daemons.

Meanwhile I tried to install the java-dbus, but got Unable to locate package java-dbus. Ha while Iḿ typing this your comment comes in (great tool this github). I already found libdbus-java which will also install dbus-java-bin. Versions 2.8-4. But sadly enough this fails. Got Conversion from character set 'ISO-8859-15' to 'UTF-8' is not supported. Have this problem quite a while now, and I still haven't found a solution for it.

Maybe you can try to run omxplayer.bin or adjust the omxplayer script NOT to fork the dbus-daemon.
Andyjagoe did that in issue #59.

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

how exactly are you running omxplayer.bin? I seem unable to simply run the /usr/bin/omxplayer.bin.

I don't understand why you get this error!!! are you not on raspbian?

@jimpil
Copy link
Author

jimpil commented Jan 18, 2014

this is getting weirder and weirder! I followed your advice and did what Andyjagoe did...commented out all the DBUS calls from the script and rebooted. Suddenly mdbus2 shows org.mpris.MediaPlayer2.omxplayer!!!

However before we get happy and stuff check this out:
on the same terminal:

mdbus2 org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2
=> [ERR]: No introspection data for object '/org/mpris/MediaPlayer2'

ListDBus
=>Exception in thread "main" org.freedesktop.dbus.exceptions.DBusException: Cannot Resolve Session Bus Address
at org.freedesktop.dbus.DBusConnection.getConnection(DBusConnection.java:267)
at org.freedesktop.dbus.bin.ListDBus.main(ListDBus.java:53)

CreateInterface -s -f org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2
=>ERROR: Failure in DBus Communications: Cannot Resolve Session Bus Address

DBusViewer
=> a GUI saying that it cannot resolve Session bus address!

weird stuff yes?

@jehutting
Copy link

Hi Jim,

I'm also on raspbian and what I meant using omxplayer.bin directly is that one should

LD_LIBRARY_PATH=/opt/vc/lib:/usr/lib/omxplayer:$LD_LIBRARY_PATH /usr/bin/omxplayer.bin ...

Without it you are indeed unable to run omxplayer.

For my 'conversion' problem, I solved that finally. For someone interested in that, seems to be that you MUST have en_US as one of your locales. I only had 'en' and 'nl' (=dutch). Silly me thinking I could live without these Americans :-))

Anyway it is great to see that WITHOUT the dbus-daemon forking in the script mdbus2 is showing omxplayer! That is really great. Seems mdbus2 has trouble with the forked daemon, or only recognizes this one as the ONLY valid one. I'm just guessing here! But what if it does do so? How is that forked dbus-daemon session'ed to omxplayer. Or is there always ONLY ONE D-Bus SESSION active? Really don't know. Have to dive more into D-Bus to figure that out. But that is more for issue #59.

Being able to install the java stuff, I ran into some /usr/lib/jvm/default-java not found error. Installed oracle jdk, but that didn't solved it. Turns out default-java is just a link to your selected jdk. I choose default-java -> java-7-openjdk-armhf. So now I could be become a Raspberry Pi Java programmer ?-). Nice.

$ mdbus2
org.freedesktop.DBus
org.mpris.MediaPlayer2.omxplayer
$ CreateInterface --session --create-files org.mpris.MediaPlayer2.omxplayer
ERROR: Could not find introspection file: org.mpris.MediaPlayer2.omxplayer (No such file or directory)
$ mdbus2 org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2
[ERR]: No introspection data for object '/org/mpris/MediaPlayer2'
$ ListDBus
Exception in thread "main" org.freedesktop.dbus.exceptions.DBusException: Cannot Resolve Session Bus Address
    at org.freedesktop.dbus.DBusConnection.getConnection(DBusConnection.java:267)
    at org.freedesktop.dbus.bin.ListDBus.main(ListDBus.java:53)
$ CreateInterface -s -f org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2
ERROR: Failure in DBus Communications: Cannot Resolve Session Bus Address

Bummer. But...nevertheless.. I would say.. so far so good.

@jimpil
Copy link
Author

jimpil commented Jan 19, 2014

Good-morning Jozef,

I do appreciate your efforts....let's summarize the situation common to us:

  • launching omxplayer from the official script means that it responds to keystrokes but mdbus2 cannot find the DBUS-address
  • launching it from omxplayer.bin means that keyboard is unresponsive but mdbus2 can report the exact DBUS-address
  • None of us can actually query the remote object, due to Failure in DBus Communications: Cannot Resolve Session Bus Address.

According to this link (http://www.mabishu.com/blog/2010/11/15/playing-with-d-bus-interface-of-spotify-for-linux/)
doing mdbus2 org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 should report a bunch of method/property definitions.

Also, I should have said that last night but my original CreateInterface (with one argument) command is wrong. The one arg overload expects an XML file-path whereas the 2-arg overload expects the DBUS-address and the remote object name. Your last command from your last response gets it right:

CreateInterface -s -f org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2

but it still fails for you too!!!

Also, now that you have Java, could you also try DBusViewer with no arguments? you should get a GUI with 2 tabs: session and system...

Do you get a responsive keyboard when running omxlayer.bin directly?

@jimpil
Copy link
Author

jimpil commented Jan 19, 2014

After a moment of enlightenment, I sat on my ubuntu desktop-pc, fired up VLC, which also implements the org.mpris.MediaPlayer2 contract, and tried the exact same command:
CreateInterface -s -f org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2

I am happy to report that I finally got my Java interfaces, under the correct directory hierarchy!!! YAY!!!
From a quick glance, the code generated seems to have nothing specific to VLC, so presumably it would be the same for omxplayer.

I guess that I can now start programming against those interfaces, but at some point I am going to have to test my code against omxplayer.

@jehutting
Copy link

Hi Jim, that was a great idea you had 🎱

I am still trying to understand D-Bus. From what I understand from the CreateInterface call is that it does an Introspect call/request to -in our case- omxplayer interface. From OMXControl code I don't see anything what looks like supporting this request. It should give some XML back. I think that CreateInterface makes there a nice Java code (class??) out of it.

Ha ha ha...I tried to do the same as you did. But now I'm having the same problem as you had with the RPI; mdbus2 not recognizes vlc, and vlc doesn't provide any services. Unbelievable ;)))))

@jimpil
Copy link
Author

jimpil commented Jan 19, 2014

If I understand correctly, any org.mpris.MediaPlayer2 should support the Introspectable interface. Alternatively it should provide the XML interface definition somehow...

Yes, CreateInterface, querys the Introspectable remote object, generates the XML and from that it generates the java source files (only interfaces).

VLC uses DBUS for more that 2 years now...I find it very weird mdbus2 doesn't show it! Actually it should show something like this:

:~$ mdbus2|grep vlc
org.mpris.MediaPlayer2.vlc
org.mpris.MediaPlayer2.vlc-2973

are you on VLC 2 or greater?

In any case, I now have the interface and after quite a bit of fiddling I managed to compile everything! I am confused because I thought that all I had to do was to write a wrapper class (satisfying all 3 interfaces) that delegates to the actual remote object. I am having trouble finding a nice tutorial and so now I am not sure which remote object to use as the code says nothing about omxplayer. The remote object is a MediaPlayer2 which is confusing because how will it distinguish between 2 players?

anyway I can't even test it against vlc because I get exceptions that no service is provided with the name org.mpris.MediaPlayer2. Why does it have to be so hard?!!!

@jehutting
Copy link

Hi Jim,

I have VLC 2.0.5. Maybe I have to plug-in something.

But I also have guayadeque, which also supports MPRIS2.

On my Linux Mint PC

$mdbus2
org.mpris.MediaPlayer2.guayadeque
$qdbus  org.mpris.MediaPlayer2.guayadeque /
property read bool org.mpris.MediaPlayer2.CanQuit
property read bool org.mpris.MediaPlayer2.CanRaise
property read bool org.mpris.MediaPlayer2.CanSetFullscreen
property read QString org.mpris.MediaPlayer2.DesktopEntry
property readwrite bool org.mpris.MediaPlayer2.Fullscreen
property read bool org.mpris.MediaPlayer2.HasTrackList
property read QString org.mpris.MediaPlayer2.Identity
property read QStringList org.mpris.MediaPlayer2.SupportedMimeTypes
property read QStringList org.mpris.MediaPlayer2.SupportedUriSchemes
method void org.mpris.MediaPlayer2.Quit()
method void org.mpris.MediaPlayer2.Raise()
property read bool org.mpris.MediaPlayer2.Player.CanControl
property read bool org.mpris.MediaPlayer2.Player.CanGoNext
property read bool org.mpris.MediaPlayer2.Player.CanGoPrevious
property read bool org.mpris.MediaPlayer2.Player.CanPause
property read bool org.mpris.MediaPlayer2.Player.CanPlay
property read bool org.mpris.MediaPlayer2.Player.CanSeek
property readwrite QString org.mpris.MediaPlayer2.Player.LoopStatus
property read double org.mpris.MediaPlayer2.Player.MaximumRate
property read QVariantMap org.mpris.MediaPlayer2.Player.Metadata
property read double org.mpris.MediaPlayer2.Player.MinimumRate
property read QString org.mpris.MediaPlayer2.Player.PlaybackStatus
property read qlonglong org.mpris.MediaPlayer2.Player.Position
property readwrite double org.mpris.MediaPlayer2.Player.Rate
property readwrite bool org.mpris.MediaPlayer2.Player.Shuffle
property readwrite double org.mpris.MediaPlayer2.Player.Volume
method void org.mpris.MediaPlayer2.Player.Next()
method void org.mpris.MediaPlayer2.Player.OpenUri(QString Uri)
method void org.mpris.MediaPlayer2.Player.Pause()
method void org.mpris.MediaPlayer2.Player.Play()
method void org.mpris.MediaPlayer2.Player.PlayPause()
method void org.mpris.MediaPlayer2.Player.Previous()
method void org.mpris.MediaPlayer2.Player.Seek(qlonglong Offset)
signal void org.mpris.MediaPlayer2.Player.Seeked(qlonglong Position)
method void org.mpris.MediaPlayer2.Player.SetPosition(QDBusObjectPath TrackId, qlonglong Position)
method void org.mpris.MediaPlayer2.Player.Stop()
property read bool org.mpris.MediaPlayer2.TrackList.CanEditTracks
property read QList<QDBusObjectPath> org.mpris.MediaPlayer2.TrackList.Tracks
method void org.mpris.MediaPlayer2.TrackList.AddTrack(QString Uri, QDBusObjectPath AfterTrack, bool SetAsCurrent)
method QDBusRawType::aa{sv} org.mpris.MediaPlayer2.TrackList.GetTracksMetadata(QList<QDBusObjectPath> TrackIds)
method void org.mpris.MediaPlayer2.TrackList.GoTo(QDBusObjectPath TrackId)
method void org.mpris.MediaPlayer2.TrackList.RemoveTrack(QDBusObjectPath TrackId)
signal void org.mpris.MediaPlayer2.TrackList.TrackAdded(QVariantMap Metadata, QDBusObjectPath AfterTrack)
signal void org.mpris.MediaPlayer2.TrackList.TrackListReplaced(QList<QDBusObjectPath> Tracks, QDBusObjectPath CurrentTrack)
signal void org.mpris.MediaPlayer2.TrackList.TrackMetadataChanged(QDBusObjectPath TrackId, QVariantMap Metadata)
signal void org.mpris.MediaPlayer2.TrackList.TrackRemoved(QDBusObjectPath TrackId)
property read bool org.mpris.MediaPlayer2.Playlists.ActivePlaylist
property read QStringList org.mpris.MediaPlayer2.Playlists.Orderings
property read uint org.mpris.MediaPlayer2.Playlists.PlaylistCount
method void org.mpris.MediaPlayer2.Playlists.ActivatePlaylist(QDBusObjectPath PlaylistId)
method QDBusRawType::a(oss) org.mpris.MediaPlayer2.Playlists.GetPlaylists(uint Index, uint MaxCount, QString Order, bool ReverseOrder)
signal void org.mpris.MediaPlayer2.Playlists.PlaylistChanged(bool Playlist)
$ CreateInterface -s -f org.mpris.MediaPlayer2.guayadeque  /org/mpris/MediaPlayer2
WARNING: Ignoring property
...<mulitple times>...

You should recognize some things from your CreateInterface call. CreateInterface fails here too; no java code just bloody warnings ignoring properties ?-)

So above output shows what you can do with connection (DESTINATION) 'org.mpris.MediaPlayer2.guayadeque' to OBJECT_PATH '/org/mpris/MediaPlayer2' through INTERFACE 'org.mpris.MediaPlayer2.Player' with a MEMBER (e.g. PlaybackStatus).

$dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.guayadeque /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'
method return sender=:1.147 -> dest=:1.153 reply_serial=2
   variant       string "Stopped"

As you can see it tells me that the player is 'Stopped' and that's correct! The music just stopped playing. Great isn't it!?

What also sould work is

$dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.guayadeque /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus

but that miserably fails. Don't know why?

By the way, DESTINATION is a unique connection name. It identifies the application on the D-Bus. Other application use this to connect (though D-Bus ;-) to that application.

Another great music player is Clementine, also supporting the MPRIS2 interface.

Running BOTH players, you get with mdbus2 :

$ mdbus2 | grep -i mpris
org.mpris.MediaPlayer2.clementine
org.mpris.MediaPlayer2.guayadeque
org.mpris.clementine
org.mpris.guayadeque

The last 2 are for MPRIS1 interfacing.

Now when playing with vlc the DESTINATION should be 'org.mpris.MediaPlayer2.vlc'. I guess... change in above dbus-send command ONLY the destination an see what happens.

For omxplayer the DESTINATION is 'org.mpris.MediaPlayer2.omxplayer'.

So..still, in my opinion...so far so good.

@jehutting
Copy link

Tried DBusViewer on the GUI. It shows in the SESSION tab

name = org.mpris.MediaPlayer2.omxplayer
path = /
user = <empty>
owner = 1.18
introspectable? = checked

Pressing the Introspect button gives an error window with

Introspection Failed. No reply within specified time.

Found a similar message in issue #61 and #110.

But we already knew that Introspection fails ;-).

@popcornmix
Copy link
Owner

How is this working with latest omxplayer and dbus changes?

@jehutting
Copy link

As long as omxplayer hasn't implemented the Introspectable interface, the CreateInterface command will still fail.

As dbus seems to work well (using the dbuscontrol.sh proves it) I assume that @jimpil (or others) should be able to control omxplayer with a java application despite the absent of the Introspectable interface.

@jehutting
Copy link

I vote for closing this one.

@jehutting
Copy link

@jimpil can you close this issue?

@jimpil
Copy link
Author

jimpil commented Dec 29, 2016

Sure, closing it now...

@jimpil jimpil closed this as completed Dec 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants