Plugin to listen to play/pause/... events?

Where to start - are there any existing?
Hi!

I have been using Plex for a while now and have started thinking about integrating it with EventGhost to be able to control the lighting at home when playback is started/paused. I have had a [pretty quick] look through the wiki and some apps that seemed similair, but havent actually found anything to start with. Could anyone point me in the right direction?

Basically, to start with, I would like to execute a command when playback starts and another when it stops. It would also be nice/fun to have a full list of possible hooks (Plex starting, exiting, navigating to ..., etc).

Is this doable / has someone already done it?

Thanks
/Victor

Plug-ins don’t have access to player event information, sorry.



Oh, I see. That explains why I havent found anything. Is there any other way to intercept that information, either from the client or the server?

/Victor

Sadly not… this is an issue we’ve run into ourselves. Clients don’t post any kind of information like this to the server. It’s not that we just aren’t exposing it to plug-ins; the server doesn’t know anything about what clients are doing to begin with.



It’s definitely on the list of things we’d like to do, because it’d enable some pretty cool functionality in our own apps, but it’s not been a high enough priority yet. When we do add it though, providing a way for plug-ins to hook into the event system is definitely something we’ll include.



Hey :)

I figured it out one week ago, It is working with the XBMC-plugin, but you must always ask PLEX if it is playing a file...


Here it is:

-First of all, you need the XBMC2-Plugin, set the IP to your Client-IP (e.g. 192.168.1.4 in the network / 127.0.0.1 if eventghost is running on the same computer) and the Port to 3000

-Now go to: XBMC2 ==> Experimental ==> JSONRPC

-Copy the *XBMC2:JSONRPC:* Action to a macro.

-DoubleClick the Action and change Namespace to 'Videoplayer/Audioplayer/Pictureplayer' and Method to 'State' (I only play videos, so I have only a Videoplayer, If you have more formats to listen, you need more Elements with Different Namespaces)

-Now the Action should named like *XBMC2: JSONRPC: VideoPlayer.State* (Or other players)

-Execute the Action and you should get a result in the Log-Window (You will get errors when no file is played/plex is not running)

-e.g. Result:

{
"partymode": false,
"playing": true,
"paused": true
}
==> File is playing (This is for the videoplayer, don't know how the result is for other players)

To get the Result as a long string, you have to add a Python-command after the action with the sourcecode: print eg.result

-Now execute the whole macro and see what you get as a result in the Log-window

e.g.: {u'paused': False, u'partymode': False, u'playing': True}

-Copy this line and change the Python-command to: print eg.result == {u'paused': True, u'partymode': False, u'playing': True}
(eg.result means the result of the last event)

==> So if a file is playing, you will get a true as a result when executed, false when paused/ no file playing/plex not running

-Delete the print in the Python-command ( eg.result == {u'paused': True, u'partymode': False, u'playing': True} ) and now you created an event, very good for a jump-action.

-Add a new action called Jump. DoubleClick and change the settings: If last action was succesful, jump to: (Here you jump to your macro which ,e.g., turns off the light) e.g. LightsOff

-If you have more players, you will now add a new macro for e.g. audioplayer. (*XBMC2: JSONRPC: AudioPlayer.State*) and do all steps again

-If all Players are inserted, make a new jump, but this time set it to 'always' to: e.g. LightsOn.


- The Client never tell you his state, so you have to insert a Timer (add the plugin Timer, and insert a new action from the plugin Timer), set it to infinite loops Name and Eventname to e.g. PLEX and interval to 1 second.
Now insert a new event with the name "Timer.PLEX" on top of the macro. So it will execute the macro every 1 second and ask if it is running.

- I would disable the macro or timer when plex is not running or when it is not in front (Task.Activated.Plex)

Treeview of the whole thing:

PLEX playing? *Macro*
|
- Timer.PLEX *Event*
- XBMC2: JSONRPC: VideoPlayer.State *Action*
- eg.result == {u'paused': True, u'partymode': False, u'playing': True} *Python-command*
- If successful jump to "LightsOff" *Jump*
(maybe)
- XBMC2: JSONRPC: AudioPlayer.State *Action*
- eg.result == ????? *Python-command*
- If successful jump to "LightsOff" *Jump*
.
.
.
- Jump to "LightsOn" *Jump*

LightsOff *Macro*
|
- *Do something*

LightsOn *Macro*
|
- *Do something*

PLEX activated *Macro*
|
- Task.Activated.Plex *Event*
- Timer: Start new or control running timer *Set an new Timer with the settings metioned above*

PLEX deactivated *Macro*
|
- Task.Deactivated.Plex *Event*
- Timer: Start new or control running timer *Abort the Timer*


I hope It helps :)



Would be cool if there is an easier way soon :)

Wonderwhy

@Wonderwhy: Interesting, thanks a lot. I will test this when I get some free time, but I certainly agree that it would be nice if there was an easier way. Also - how does the XBMC plugin get the data?!



Anyway, thanks again!



/Victor




The PLEX Media Center is based on XBMC, so the plugin for XBMC also works for PLEX
I also have a remote to control PLEX with the XBMC-Plugin, very nice :)

Let me know if it is working ;)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.