INTERACT FORUM

Please login or register.

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

Author Topic: Close after playback  (Read 2772 times)

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Close after playback
« on: August 16, 2011, 02:32:55 am »

Basically I'm looking for a way to launch MC from the command-line and play a video and after playback of that file has finished to have MC automatically close.

Was wanting something like this: mc16.exe /PlayReplace c:\test.mkv /Close
Doesn't work though.
Logged

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: Close after playback
« Reply #1 on: August 16, 2011, 03:10:57 pm »

Any thoughts on this?

Was wanting to use MC rather than the other media player I've been using.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #2 on: August 16, 2011, 05:25:16 pm »

I did a quick search of the command line and MCC commands but didn't see anything obvious.  

If there was a /Status command, you could have a script query every now and again to see if playback has completed.  

Or if MC had a Close After Playback Complete option, or had an way to queue up mc*.exe messages.

FYI: mc*.exe doesn't accept additional OPTIONs after the first:

mc*.exe OPTION args ...

You'd have to issue two mc*.exe commands, but since the command returns immediately, it won't be of much use.
Logged
The opinions I express represent my own folly.

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #3 on: August 16, 2011, 06:08:06 pm »

Hold on, I see a way...
Logged
The opinions I express represent my own folly.

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: Close after playback
« Reply #4 on: August 16, 2011, 06:21:10 pm »

Ya I had looked through the MC Commands but couldn't see a way of doing it.

I had thought of the script way as well but would need it to poll the status fairly often maybe once a second or maybe 2. Wasn't sure if there would be some performance impact on the system doing that though... but couldn't see a way of getting the playing status anyways, so....
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #5 on: August 16, 2011, 06:57:21 pm »

Ok, this is pretty straightforward, but it will depend on the tools you have / are comfortable with.  I put together a quick cygwin bash script.  I didn't want to waste time with windows cmd scripting.

it uses curl to send the HTTP request to the MC media server, uses perl to parse the resulting State information, and loops until an empty or 0 state result is returned.  I set a sleep interval at the beginning of the loop so that you can run the script immediately after launching MC, so that it's services have time to initialize.

Change the AUTHUSERNAME and AUTHPASSWD to your own settings under Options > Media Network > Authentication, and MC_IP_ADDR to your server's IP address. Unless you've changed the port, it should be 52198 (Options > Media Network > Advanced > TCP Port).

Code: [Select]
#!/usr/bin/bash

while : ; do
    sleep 10
    status=$(curl --silent --user AUTHUSERNAME:AUTHPASSWD http://MC_IP_ADDR:52198/MCWS/v1/Playback/Info?Zone=-1 |
            perl -ne 'print "$1\n" if s/^.*State">(\d+)<.*$/\1/s;');
        if [ -z "$status" ] ; then
            echo MC not running
            break
        elif [ $status -eq 0 ] ; then
            echo MC playback is stopped - closing...
            mc16.exe /Close
            break
        fi
        echo MC status: $status
done

I launched MC, and started a track (and advanced it until the last 40 seconds or so).  Running the script...

Code: [Select]
$ ./mc.bash
MC status: 2
MC status: 2
MC status: 2
MC status: 2
MC playback is stopped - closing...

That's it.

Logged
The opinions I express represent my own folly.

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 71603
  • Where did I put my teeth?
Re: Close after playback
« Reply #6 on: August 16, 2011, 07:33:27 pm »

gasp!
Logged

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: Close after playback
« Reply #7 on: August 16, 2011, 08:42:31 pm »

Thank you very much MrC.

I'm not familiar at all with bash scripting but can understand the concept of what that code is doing. I'm more familiar with vbs, not an expert but can make my way through it. Think I'll try and replicate what you did in a vb script. That was very helpful though.

Thanks
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #8 on: August 16, 2011, 09:44:09 pm »

You're welcome.  It was really a proof of concept; I suspected you'd not have these tools available (but they're free and easy if you're interested, and want help).

You can see the value you're looking for if you enter the URL into the browser.  Look for Status.  Reload the page when MC is playing a track and when it is not.
Logged
The opinions I express represent my own folly.

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: Close after playback
« Reply #9 on: August 17, 2011, 04:41:34 pm »

Ok, here's what I came up with. Seems to work fairly well. It requires at least 3 parameters to be passed to it, file path, zone to play in and screen mode to play in. A 4th can be passed to either shutdown, standby or hibernate the computer after playback stops.

Play test.avi in zone 0 in fullscreen:
mcplayclose.vbs "c:\test.avi" 0 fullscreen

Play test.avi in zone 1 in fullscreen then standby after playback has stopped:
mcplayclose.vbs "c:\test.avi" 0 fullscreen standby 

Play the playlist "myplaylist" in zone 0 in fullscreen then shutdown after playback has stopped:
mcplayclose.vbs "TREEPATH=Playlists\myplaylist" 0 fullscreen shutdown

I have 2 uses for this myself. 1) I like to have some music playing at night when I go to bed and can use this to playback a playlist then put the computer into standby after it has finished. 2) Using it for a friend that is using another program to manage his video collection and wants that program to launch MC as the player.

Any feed back is welcome.


Code: [Select]
' First 3 parameters are required. The 4th shutdown parameter can be left off.
' Parameter 1 is the path to the file to play. Must be given otherwise script will just quit.
' Parameter 2 is the zone to play the file in. Must be by zone index, zone1 is index 0, zone2 is index 1....
' Parameter 3 specifies which mode to play in: Standard, Minime, Fullscreen or Theater
' Parameter 4 specifies to shutdown, standby or hibernate after closing. Must be lower case.
' Sets Repeat off for the specified zone otherwise play never stops and MC never closes and script will continue to run.
' example: mcplayclose.vbs "c:\test.avi" 0 fullscreen
' example: mcplayclose.vbs "c:\test.avi" 0 fullscreen standby 
' example: mcplayclose.vbs "TREEPATH=Playlists\myplaylist" 0 fullscreen standby

Dim state, xmlSuccess, objShell, mcURL, filearg, zonearg,_
shutdownarg, screenarg, mcIP, mcPort, mcUserName, mcPassword

mcIP = "127.0.0.1" 'set to your library server IP address
mcPort = "52199" 'set to your library server port number
mcUserName = "" 'set to your library server username
mcPassword = "" 'set to your library server password

Select Case WScript.Arguments.Count
Case 0
WScript.Quit
Case 1
Set args = WScript.Arguments
filearg = args.Item(0)
zonearg = "0"
screenarg = ""
shutdownarg = ""
Case 3
Set args = WScript.Arguments
filearg = args.Item(0)
zonearg = args.Item(1)
screenarg = args.Item(2)
shutdownarg = ""
Case 4
Set args = WScript.Arguments
filearg = args.Item(0)
zonearg = args.Item(1)
screenarg = args.Item(2)
shutdownarg = args.Item(3)
Case Else
WScript.Quit
End Select

if mcUserName = "" then
mcURL = "http://" & mcIP & ":" & mcPort & "/MCWS/v1/Playback/Info?Zone=" & zonearg & "&ZoneType=Index"
else
mcURL = "http://" & mcUserName & ":" & mcPassword & "@" & mcIP &_
":" & mcPort & "/MCWS/v1/Playback/Info?Zone=" & zonearg & "&ZoneType=Index"
end if

Set objShell=WScript.CreateObject("WScript.Shell")
if screenarg <> "" then
objShell.run "C:\Windows\System32\MC16.exe /Mode " & screenarg
WScript.sleep 2000     ' Give MC time to load before issuing next command
end if
objShell.run "C:\Windows\System32\MC16.exe /PlayReplace " & filearg & "|Zone=" & zonearg & "&ZoneType=Index"

WScript.sleep 15000     'Waits 15 seconds for MC's server to initialize, may need to be longer on slower computers
'If you have MC Server set to run at startup then this can be disabaled.
objShell.run "C:\Windows\System32\MC16.exe /MCC 10006, 1:" & zonearg & "&ZoneType=Index"     'Turn off repeat
Set xmlMC = CreateObject("Msxml2.DOMDocument")
xmlMC.async = False

Do
xmlSuccess=xmlMC.load(mcURL) '& "/MCWS/v1/Playback/Info?Zone=" & zonearg & "&ZoneType=Index")
if xmlSuccess <> "True" then
WScript.Echo "Can't Connect to MC"
Set objShell = Nothing
Set xmlMC = Nothing
Set ItemList = Nothing
WScript.Quit
end if
Set ItemList = xmlMC.selectNodes("/Response/Item")
state = ItemList.item(0).Text     'Item 0 in the xml is MC state,value of 0=stopped 1=paused 2=playing
WScript.sleep 2000
Loop While state <> 0

objShell.run "C:\Windows\System32\MC16.exe /Close"

Set xmlMC = Nothing
Set ItemList = Nothing
WScript.sleep 5000
Select Case shutdownarg
Case "shutdown"
objShell.Run "%windir%\System32\shutdown.exe -s -t 0"
Case "standby"
objShell.Run "%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Standby"
Case "hibernate"
objShell.Run "%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState Hibernate"
end Select
Set objShell = Nothing
WScript.Quit
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #10 on: August 17, 2011, 04:54:22 pm »

You picked up and ran with this, to be sure!  Nice work.

FYI: I've seen a State 3, while running.   Not sure of the difference between 2 and 3.
Logged
The opinions I express represent my own folly.

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 42028
  • Shoes gone again!
Re: Close after playback
« Reply #11 on: August 17, 2011, 05:09:35 pm »

You picked up and ran with this, to be sure!  Nice work.

FYI: I've seen a State 3, while running.   Not sure of the difference between 2 and 3.


enum EPlayerStates
{
   PlayerState_Stop = 0,
   PlayerState_Pause,
   PlayerState_Play,
   PlayerState_Wait,
   PlayerState_Count,
};

So 3 is "wait" like when we're buffering at the beginning or stopping at the end.

Functionally just consider (State != PlayerState_Stop) to be playing.
Logged
Matt Ashland, JRiver Media Center

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Close after playback
« Reply #12 on: August 17, 2011, 05:14:05 pm »

Thanks, that makes sense.  I saw 3 only when starting playback.
Logged
The opinions I express represent my own folly.

justsomeguy

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 525
Re: Close after playback
« Reply #13 on: August 17, 2011, 05:20:20 pm »

Thanks for the clarification on that Matt.

I noticed there is a "Status" in the Playback/info xml. Is that a reliable way of determining play state?
Logged
Pages: [1]   Go Up