Page 1 of 1

Question/Bug for the MM team

Posted: Wed Jan 11, 2006 6:04 am
by trixmoto
I have stripped down my code as much as possible to highlight this bug for you.

The first script is a ScriptType=2 so runs when a track plays. All it does is look for and run a second script file.

Code: Select all

Sub CueReader
  cuef = SDB.ApplicationPath&"Scripts\CueReader2.vbs"
  If SDB.Tools.FileSystem.FileExists(cuef) Then
    Set WShell = CreateObject("WScript.Shell")
    line = "wscript "&Chr(34)&cuef&Chr(34)
    res = WShell.Run(line, 1, 1)
  End If
End Sub
Then the second script (CueReader2.vbs) contains a simple loop which will continue whilst the player is playing.

Code: Select all

Set SDB = CreateObject("SongsDB.SDBApplication")
Do while SDB.Player.isPlaying  
  WScript.Sleep 200
Loop
Now try this:
1) Play a file so the first script starts (which starts the second script and ends).
2) Click on some node/playlist so another track appears in the library window.
3) Press stop on the player (which ends the second script).

The song that is first in the library window will now start playing. It doesn't always happen. But about 80% of the time it does. Any ideas?

Posted: Wed Jan 11, 2006 9:13 am
by psyXonova
Well Trix, you post troubled me....
So i digged a bit.

I tried the following code

Code: Select all

Sub CueReader
  cuef = SDB.ApplicationPath&"Scripts\CueReader2.vbs"
  If SDB.Tools.FileSystem.FileExists(cuef) Then
    Set WShell = CreateObject("WScript.Shell")
    line = "wscript "&Chr(34)&cuef&Chr(34)
    res = WShell.Run(line, 1, 1)
  End If

MsgBox "Cue Reader just finished"
End Sub
And

Code: Select all

Set SDB = CreateObject("SongsDB.SDBApplication")
Do while SDB.Player.isPlaying 
  WScript.Sleep 200
Loop 

MsgBox "Monitor just finished"
Guess what, monitor was exiting before the cuereader, since the first script was paused while the second was running. After the monitor exits the first script reevaluates the if statement, causing the the second script to run again and also causing the MM player to restart.
Now, i dont know why this happens only if the current songlist has changed. Perhaps its a bug...

The point is that i found a workaround

if you execute the second script like this

Code: Select all

    res = WShell.Run(line, 1, 0)
Then, the first script dont wait for the second and terminates. This eliminates this bug

Hope this helps

Posted: Wed Jan 11, 2006 9:58 am
by trixmoto
Cheers, once again you have prevailed! :)

Posted: Wed Jan 11, 2006 10:15 am
by Peke

Code: Select all

WShell.Run(line, 1, 0)
Is windows command and when it is executed that way it waits for return Command :) No bug there.

Posted: Wed Jan 11, 2006 10:26 am
by psyXonova
yes Peke, but the question is...
why does the playback starts after all?
and why does this happens only on node change?
It may not be a bug, but is quite strange

@Trix
Just glad to be of help Trix. Sometimes when you have written 1000 lines of code is hard to realize where the problem resides. A look from a second codes is always better in those occasions, thats why i solved that problem of yours. All credits to you!!!

Posted: Wed Jan 11, 2006 11:39 am
by Peke
yes Peke, but the question is...
why does the playback starts after all?
It is On Play Script not On track Change script.

Its better said Pre-Play Script.
and why does this happens only on node change?
Explain that.

Posted: Mon Jan 23, 2006 5:48 pm
by trixmoto
Ok, the three arguments for the Run method.

1) The command string
2) A number which represents the window style.
3) Whether the script should wait for a response (true/false)

What do the window style numbers respresent?

ADDITION: Having searched for AGES through a lot of rubbish, I found this rather useful link: http://www.ss64.com/wsh/run.html

Posted: Tue Jan 24, 2006 3:41 am
by jiri
It seems to be the same parameter as SW_ constants in e.g. ShowWindow() WinAPI function, so in case you need it, more details could be found in MSDN.

Jiri

Posted: Tue Jan 24, 2006 7:09 am
by psyXonova
Trix, there is a detailed description of each command inside Microsoft's Scripting Guide.
You can download it from srcipting.microsoft.com

Posted: Tue Jan 24, 2006 7:39 am
by trixmoto
Thanks. Here is a more direct link for anyone who is interested: http://www.microsoft.com/downloads/deta ... laylang=en