INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Script for one-click playback [SDK example]  (Read 7195 times)

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Script for one-click playback [SDK example]
« on: March 18, 2013, 05:35:58 pm »

18.0.153 makes some new things possible with the command line and web service.

I was looking for a way to make it really easy to get background music playing at home.

This batch file runs the program, stops what's playing, links zones (you need zones named 'Kitchen' and 'Living Room'), sets the volume, then starts Play Doctor playing.

Code: [Select]
REM --------------------------------
REM JRiver One-Click Play Batch File
REM --------------------------------

REM Make sure MC is running
MC18.exe

REM Stop playback of anything that might be playing
MC18.exe "/MCWS/v1/Playback/Stop?Zone=Kitchen&ZoneType=Name"
MC18.exe "/MCWS/v1/Playback/Stop?Zone=Living Room&ZoneType=Name"

REM Link zones
MC18.exe "/MCWS/v1/Playback/LinkZones?Zone1=Kitchen&ZoneType1=Name&Zone2=Living Room&ZoneType2=Name"

REM Set volume for each zone
MC18.exe "/MCWS/v1/Playback/Volume?Zone=Kitchen&ZoneType=Name&Level=0.65"
MC18.exe "/MCWS/v1/Playback/Volume?Zone=Living Room&ZoneType=Name&Level=0.75"

REM Start Play Doctor playback
MC18.exe "/MCWS/v1/Playback/PlayDoctor?Seed=Easy Listening&Zone=Living Room&ZoneType=Name"

Someday I'd like to get it so my phone could wake up the computer and run the script with a single click.  Gizmo already does the wake up part, so this might not be too hard.
Logged
Matt Ashland, JRiver Media Center

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4887
Re: Script for one-click playback [SDK example]
« Reply #1 on: March 18, 2013, 07:45:18 pm »

Matt, do you know whether this functionality will allow me to control MC using iRule on my iPad? I currently have a few commands working using WMC commands with MCE Controller working on the HTPC, but not everything worked at the time I programmed it. However, at that point MC was having some troubles with remote commands, so I'm not sure whether to try again.
Logged

raym

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3583
Re: Script for one-click playback [SDK example]
« Reply #2 on: March 18, 2013, 07:52:27 pm »

Hi Matt,

Is it possible to query the play state using calls like this? - ie, stopped, paused, playing? If not, could this be added. I'm looking for a way to do stuff based on the current play state if possible.

Thanks.
Logged
RKM Smart Home - www.rkmsmarthome.com.au
Z-Wave Home Automation

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Script for one-click playback [SDK example]
« Reply #3 on: March 18, 2013, 08:03:32 pm »

So it appears the command line processor will look for /MCWS and then issue the command.  Nice.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #4 on: March 18, 2013, 08:15:37 pm »

Hi Matt,

Is it possible to query the play state using calls like this? - ie, stopped, paused, playing? If not, could this be added. I'm looking for a way to do stuff based on the current play state if possible.

Thanks.

It doesn't return information to the command line.

So to do something like that now, you'll have to use the MCWS directly or COM.

It would be nice if the command line returned the same result you'd get in a browser, but the plumbing is a little complicated.

EDIT: Thinking about this a little more, I wonder if we could just allow any MCWS function to accept a parameter like &OutputToFile=C:\Test.dat.  Then, the launcher could append that and read the file after it finished.  It could then write the file to the standard output.  It would remove the need to tunnel (possibly large) data back through a memory map or other IPC mechanism.
Logged
Matt Ashland, JRiver Media Center

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #5 on: March 18, 2013, 08:16:35 pm »

So it appears the command line processor will look for /MCWS and then issue the command.  Nice.

Exactly.

I'm particularly keen to build functionality into MCWS, so it makes sense to allow the other ways to control the program to tunnel into it.
Logged
Matt Ashland, JRiver Media Center

raym

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 3583
Re: Script for one-click playback [SDK example]
« Reply #6 on: March 18, 2013, 09:52:19 pm »

EDIT: Thinking about this a little more, I wonder if we could just allow any MCWS function to accept a parameter like &OutputToFile=C:\Test.dat.  Then, the launcher could append that and read the file after it finished.  It could then write the file to the standard output.  It would remove the need to tunnel (possibly large) data back through a memory map or other IPC mechanism.

That'd work!
Logged
RKM Smart Home - www.rkmsmarthome.com.au
Z-Wave Home Automation

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Script for one-click playback [SDK example]
« Reply #7 on: March 18, 2013, 10:57:19 pm »

If the launcher is going to have the ability to read this temp file, just make it an anonymous private file that MC manages and outputs.

I think you are going to eventually need to create cross platform fork, exec, and pipe functions for handling process creation and the STDIO plumbing and errno reporting.  It is not very difficult, btw.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #8 on: March 19, 2013, 03:57:55 pm »

I think you are going to eventually need to create cross platform fork, exec, and pipe functions for handling process creation and the STDIO plumbing and errno reporting.  It is not very difficult, btw.

The launcher isn't actually a command line program.  This way, it doesn't show a terminal window when it's run.

But that means it's hard to write the output to the command line.

There's some discussion of this here:
http://stackoverflow.com/questions/54536/win32-gui-app-that-writes-usage-text-to-stdout-when-invoked-as-app-exe-help

Maybe creating an MC18.com file would work.  I'm not sure.

Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Script for one-click playback [SDK example]
« Reply #9 on: March 19, 2013, 04:26:31 pm »

Oh, I see. I thought it was a command line program, that was configured to not show the command line window (this is possible).  So I'm guessing it is just MC (or nearly), stripped down to the bare essentials.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #10 on: March 19, 2013, 04:31:03 pm »

I thought it was a command line program, that was configured to not show the command line window (this is possible).

Is that possible from code, in such a way that a black box won't flash at all?


Quote
So I'm guessing it is just MC (or nearly), stripped down to the bare essentials.

It's just a tiny stand-alone executable that forwards commands to the right place.  It's not really like MC (other than that it's built on the same base classes).
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Script for one-click playback [SDK example]
« Reply #11 on: March 19, 2013, 05:23:20 pm »

Is that possible from code, in such a way that a black box won't flash at all?

Let's see, its been a while...

Use CreateProcess().  In the LPSTARTUPINFO structure, set dwFlags with STARTF_USESHOWWINDOW, and set SW_HIDE in wShowWindow.

Ages ago I had to write some cross-platform (WinNT, *nix) commmand line progs for a client, and created wrapper functions for the *nix/POSIX fork/exec/pipe, etc. system calls.  This made the STDIO pretty trivial and much more useful than typical Win32 console apps.

Also see: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/4539b247-9f35-422f-99e0-b4c341c7c004/
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #12 on: March 19, 2013, 05:35:52 pm »

Let's see, its been a while...

Use CreateProcess().  In the LPSTARTUPINFO structure, set dwFlags with STARTF_USESHOWWINDOW, and set SW_HIDE in wShowWindow.

That only works if we're launching.

But double-clicking an MP3 from Explorer runs the launcher, etc. and in those cases, we can't control the process launch flags.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Script for one-click playback [SDK example]
« Reply #13 on: March 19, 2013, 05:43:21 pm »

... hence the aforementioned link.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42373
  • Shoes gone again!
Re: Script for one-click playback [SDK example]
« Reply #14 on: March 19, 2013, 08:01:30 pm »

... hence the aforementioned link.

I think they're just switching from a console program to a GUI program without really realizing it (wmainCRTStartup entry point).

Maybe if a GUI program is opened from the console there's a way to write to the output, but I don't think so because the console doesn't wait for the process to finish.
Logged
Matt Ashland, JRiver Media Center

Dan64

  • Member
  • *
  • Posts: 1
Re: Script for one-click playback [SDK example]
« Reply #15 on: March 31, 2013, 05:03:34 pm »

I have wrote a little utility to launch the playback of a movie in full screen. The usage it's simple:

jremote "mediafile"
or
jremote "playlist"

other options are in the file: jremote.exe.config

In summary the utility perform the following tasks:

1) Check if JRiver MediaServer is running if not start it. 2) Set JRiver Player in full screen. 3) Ask to MediaServer to play the film, also should accepts play lists as file name. 4) For 10 secs. attempt to give the focus to the Player. 5) Stay in idle till some hot keys are pressed then close JRiver MediaServer and exit.

The hot keys are: ALT+F4, CTRL+S, BACK, ESC


I have attached the file (with C# source) in this post.

Also since this feature is missing in JRiver: if is pressed APPS or More/Info on the remote is shown a media info display over the screen. To work it's necessary copy in the same folder of this utility the file "mediainfo.dll" (link: http://mediaarea.net/download/binary/libmediainfo0/0.7.62/MediaInfo_DLL_0.7.62_Windows_i386_WithoutInstaller.7z).
Logged

sonata31

  • Junior Woodchuck
  • **
  • Posts: 67
Re: Script for one-click playback [SDK example]
« Reply #16 on: April 14, 2013, 09:10:16 am »

Is it possible to start MC and ask him to remove all video of the library (not the music) and import a file mpl, by a command line ?
Logged

6233638

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 5353
Re: Script for one-click playback [SDK example]
« Reply #17 on: April 14, 2013, 09:32:03 am »

Is it possible to start MC and ask him to remove all video of the library (not the music) and import a file mpl, by a command line ?
http://wiki.jriver.com/index.php/The_Command_Line

It doesn't look like you can remove items from the library via the command line, but you can import & play files.
Logged

sonata31

  • Junior Woodchuck
  • **
  • Posts: 67
Re: Script for one-click playback [SDK example]
« Reply #18 on: April 14, 2013, 12:39:43 pm »

Thank you, I'll look
Logged
Pages: [1]   Go Up