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?
'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