INTERACT FORUM

Please login or register.

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

Author Topic: Automatically closing MC via a batch file  (Read 864 times)

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Automatically closing MC via a batch file
« on: June 03, 2022, 04:33:05 pm »

I use batch files that contain MC commands to play a sequence of video clips. These batch files are triggered from PowerPoint presentations and I would like to find a way to automatically close MC after the last video in the batch file has played. This would smooth the transition back to PowerPoint.

My first thought was to add MC29.exe /Close to the end of a batch file, but this causes MC to close before it has played any of the preceding video clips in the batch file. Is there another method that would meet my needs?
Logged

fitbrit

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4877
Re: Automatically closing MC via a batch file
« Reply #1 on: June 03, 2022, 05:26:12 pm »

Can you introduce a delay that is long enough to play the videos? I've played with Unified Remote launching a BAT file to restart MC. It closes MC, has a 3 second delay and then closes MC.
Could you?:

Start MC
Start playback
Have a delay from playback start
Stop MC
Logged

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #2 on: June 04, 2022, 04:44:50 am »

Can you introduce a delay that is long enough to play the videos? I've played with Unified Remote launching a BAT file to restart MC. It closes MC, has a 3 second delay and then closes MC.
Could you?:

Start MC
Start playback
Have a delay from playback start
Stop MC

Many thanks for that idea. I ran a test with the following two lines added to the end of one of my batch files.

Code: [Select]
Timeout 20 /nobreak
MC29.exe /Close

The first video clip in the batch file then played for 20 seconds and MC was then closed down. Your suggestion therefore does work, but it would require me to spend time working out the exact total duration of the video clips (and some audio clips) in each of my batch files. I've previously noticed that MC takes a little longer to open if it's the first time that day, so I guess I might have to add a second or two to the calculated Timeout value to avoid premature closure. 

Shortly after making my post, I realised that Windows might have a keyboard shortcut for closing the current app. A quick Google search found that Alt+F4 will do that job. That looks like an easier solution than using timeout delays. However, it would still be interesting to hear of any other solutions that don't require manual keyboard input.

Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Automatically closing MC via a batch file
« Reply #3 on: June 04, 2022, 02:06:18 pm »

This thread from 11 years ago talks about exactly what you are trying to do.  There's a VB Script in reply #9 that seems to do what you want.

https://yabb.jriver.com/interact/index.php?topic=65893.0

Brian.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8959
Re: Automatically closing MC via a batch file
« Reply #4 on: June 04, 2022, 02:33:04 pm »

This thread from 11 years ago talks about exactly what you are trying to do.  There's a VB Script in reply #9 that seems to do what you want.

https://yabb.jriver.com/interact/index.php?topic=65893.0

Brian.
Search ninja 🔎👁😄

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #5 on: June 04, 2022, 05:09:49 pm »

This thread from 11 years ago talks about exactly what you are trying to do.  There's a VB Script in reply #9 that seems to do what you want.

https://yabb.jriver.com/interact/index.php?topic=65893.0

Brian.

Thanks, Brian. It's getting late here in the UK now, so I'll check that out tomorrow.
Logged

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #6 on: June 04, 2022, 05:29:37 pm »

Search ninja 🔎👁😄

Hi marko. I'm not sure if your intention was to congratulate Brian on his searching skills or to gently chide me for the lack of them :)

If the latter, then my only defence is that successful searches often depend on including a key word that may only become obvious when you already know the answer. I opened this thread as my search for 'close media center using batch file' failed to generate any useful results. 

One thing is certain, this forum is a very helpful place and for that I am very grateful.
Logged

marko

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8959
Re: Automatically closing MC via a batch file
« Reply #7 on: June 04, 2022, 10:44:41 pm »

Definitely the former. I would think that success dependant on keywords searched for occurs way more than 'often'. Google is scaryily good at coming up with the goods from the most tenuous of searches, but with software, not so good. With those, I often end up with a ton of results from places like stack overflow dot com that are never really any help, even if I could understand a fraction of what they're on about :)

You in Scotland by any chance? I'm Edinburgh.

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #8 on: June 05, 2022, 08:53:07 am »

Definitely the former. I would think that success dependant on keywords searched for occurs way more than 'often'. Google is scaryily good at coming up with the goods from the most tenuous of searches, but with software, not so good. With those, I often end up with a ton of results from places like stack overflow dot com that are never really any help, even if I could understand a fraction of what they're on about :)

You in Scotland by any chance? I'm Edinburgh.

You have reminded me of long-forgotten advice I was given here several years ago to use Google (ideally with a site:jriver.com parameter) to search for solutions to Media Center problems, rather than the forum's own search tool. If I'd used Google, I'd have found that 11 year old thread very quickly!

I grew up in Edinburgh but moved to the west of Scotland for my first job after graduating from Edinburgh University. That was a very long time ago. My home is now in Southampton, but Edinburgh remains one of my favourite cities.
Logged

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #9 on: June 05, 2022, 09:21:15 am »

This thread from 11 years ago talks about exactly what you are trying to do.  There's a VB Script in reply #9 that seems to do what you want.

https://yabb.jriver.com/interact/index.php?topic=65893.0

Brian.

After making what I think are all the required configuration changes to that old VBS script (including altering all references to MC16.exe to MC28.exe), I've tried to use it to open one of my my media files. The script succeeds in opening MC and closes it again after about 20 seconds. What it doesn't do yet is to play my media file. Investigations are continuing...
Logged

haggis999

  • Galactic Citizen
  • ****
  • Posts: 471
Re: Automatically closing MC via a batch file
« Reply #10 on: June 05, 2022, 04:58:47 pm »

My previous tests of that script, which I've named as CloseMCAfterPlayback.vbs on my PC, were attempts to play either MKV video files or DSF audio files. In both cases, MC would open but no media file was played.

I've now tried again using a FLAC file and this time the music was played. However, MC was closed after 20 seconds, long before the end of the music.

Can anyone with a better understanding of the coding in CloseMCAfterPlayback.vbs explain why it fails to play MKV and DSF files that my MC installation is normally happy to play in the normal manner, and why it appears to be sensing an MC state of 0 (= stopped) while the music is still playing?

Code: [Select]
'The original version of this script was obtained from https://yabb.jriver.com/interact/index.php?topic=65893.0

' 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, Mini, Display 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: CloseMCAfterPlayback.vbs "c:\test.avi" 0 display
' example: CloseMCAfterPlayback.vbs "c:\test.avi" 0 display standby
' example: CloseMCAfterPlayback.vbs "TREEPATH=Playlists\myplaylist" 0 display standby

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

mcIP = "xxx.xxx.xxx.xxx" 'set to your library server IP address
mcPort = "52199" 'set to your library server port number
mcUserName = "xxxxx" 'set to your library server username
mcPassword = "xxxxxxxx" '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\MC28.exe /Mode " & screenarg
WScript.sleep 2000     ' Give MC time to load before issuing next command
end if
objShell.run "C:\Windows\System32\MC28.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 disabled.
objShell.run "C:\Windows\System32\MC28.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\MC28.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
Pages: [1]   Go Up