FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

Waiting for a program to be executed/perform an operation?

 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows
View previous topic :: View next topic  
Author Message
daffy
Junior Member


Joined: 14 Jan 2006
Posts: 36
Location: Erlangen, Germany

PostPosted: Sun Jan 15, 2006 6:44 pm    Post subject: Waiting for a program to be executed/perform an operation? Reply with quote

Hello again,

I am trying to write a script that does the following:
1. Let me choose a movie to playback
2. switch to TV
3. start BSPlayer
4. switch BSPlayer in to Fullscreen mode
5. start the BSPlayer Remote Script (modified with Fullscreen/Window Switch)

I already wrote all scripts seperately. They work fine.
Now I want to call one after another, but it won't work, because the script doesn´t wait for the other scripts to complete there tasks (my guess).
I tried to overcome the problem by inserting loops that wait for BSPlayer to be opened or the movie to be opend, but this results in an infinite loop, because salling clicker is using 100% of my CPU in the loop, thus not allowing BSPlayer to be started/open a movie... Without the loops, it won´t work, because the scripts are called befor BSPlayer is started or the movie is opened.

Someone got an idea?

Here is the script

var OpenUUID = "e2b76190-84ef-11da-a72b-0800200c9a66";
var BSPlayerUUID = "d5c9b560-84ee-11da-a72b-0800200c9a66";

var wsh = new ActiveXObject('WScript.Shell');
var TVToolPath = wsh.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\TVTool8\\CurrentDirectory");
var BSPlayerPath = wsh.RegRead("HKEY_CURRENT_USER\\Software\\BST\\bsplayerv1\\AppPath");
var bspwh = 0;
var status = 4;

if( TVToolPath != null ) {
//switch to TV
ActiveXObject("Shell.Application").ShellExecute(TVToolPath+"\\tvtool.exe","/tv","","",2);
}

if( BSPlayerPath != null ) {
//Open Movie
theTerminal.ExecuteScript(OpenUUID);

//wait until BSPlayer is launched and movie is opened
//!can cause an infinite loop if an error occurs!
bspwh=0;
while ( bspwh == 0 ) {
bspwh = FindWindow( "BSPlayer", "" );
}
status = 4;
while ( status != 1 && status != 2 && status != 3 ) {
status = SendMessage( bspwh, WM_BSP_CMD, BSP_GetStatus, 0 );
}

//switch to fullscreen
SendMessage( bspwh, WM_BSP_CMD, BSP_MovieMode, 0 );

//launch BSPlayer Remote Pro
theTerminal.ExecuteScript(BSPlayerUUID);
}

P.S. I also implemented the same functionality by modifiying the Open-Script. I essentially did the same and also worked with loops. It works...
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Mon Jan 16, 2006 12:19 pm    Post subject: Reply with quote

Daffy,

The structure of your script is broken.

This will (and should) return immediately:

theTerminal.ExecuteScript(OpenUUID);

This will deadlock Clicker:

while ( bspwh == 0 ) {
bspwh = FindWindow( "BSPlayer", "" );
}



I suggest you copy the code from the open script into your new script, so that you can tie into the event handlers, starting your wait loop only *after* the movie has been opened.

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
daffy
Junior Member


Joined: 14 Jan 2006
Posts: 36
Location: Erlangen, Germany

PostPosted: Mon Jan 16, 2006 4:25 pm    Post subject: Reply with quote

Ok, I understand. Your proposal works, but I wanted a "cleaner" code (it can be argued about that...). Since there seems to be no possibility to wait for a programm to be opened without blocking the computer, I had an idea.
1. create a CreateMediaplayerScreen widget with update functionality (like mykeypad_update)
(is called everey few milliseconds without blocking computer)
2. in _update first check if player is launched. If it is start openScript.
3. in _update now check if movie has been opened by player. If it has, switch to fullscreen and start bsplayer remote.

I implemented it and it works (see the code in the end).
:? BUT when I close the BSPlayer remote (the back button), the first called widget is still open and i have to close this one too, to get back to the menu.

:?: IS there a possibility to close this (or any other) widget without pressing the back-button? (Some function call?)

Here is the code:

var WM_BSP_CMD = 0x400+2;
var BSP_GetStatus = 0x10102;
var BSP_MovieMode = 44;

var OpenUUID = "FAF9BF8A-CB5F-4558-9205-98FE963538F2";
var BSPlayerUUID = "2913F9C5-7C9A-42c1-9AAF-FD29EC9AC0B4";

var wsh = new ActiveXObject('WScript.Shell');
var TVToolPath = wsh.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\TVTool8\\CurrentDirectory");
var BSPlayerPath = wsh.RegRead("HKEY_CURRENT_USER\\Software\\BST\\bsplayerv1\\AppPath");
var movieOpen = false;
var BSPlayerWidgetLaunched = false;

if( TVToolPath != null ) {
//switch to TV
//ActiveXObject("Shell.Application").ShellExecute(TVToolPath+"\\tvtool.exe","/tv","","",2);
}

if( BSPlayerPath == null ) {
var widget = CreatePopupDialog( "" ); // not interested in callbacks
widget.textualContent = "Cannot find BSPlayer.";
theTerminal.Push( widget );
exit();
}

// Check if BSPlayer is launched

var bspwh = 0;
try {
bspwh = FindWindow( "BSPlayer", "" );
} catch( e ) {
}

if( bspwh == 0 ) {
new ActiveXObject("Shell.Application").ShellExecute( BSPlayerPath, "" );
}

launchWidget();
exit();

function launchWidget()
{
var widget = CreateMediaplayerScreen( "threadcaller_" );
widget.title = "Opening Movie on TV";
widget.name = "Opening Movie on TV";
//sampleRow = widget.CreateRow( "", scCenter, scWrap, scLarge );
theTerminal.Push( widget );
}


function threadcaller_Update( theScreen )
{
try {

var bspwh = 0;
try {
bspwh = FindWindow( "BSPlayer", "" );
} catch( e ) {}

if( bspwh == 0 ) {
throw "BSPlayer not launched";
} else if (!movieOpen) {
//Open Movie
theTerminal.ExecuteScript(OpenUUID);
movieOpen=true;
} else if (movieOpen) {
var status = SendMessage( bspwh, WM_BSP_CMD, BSP_GetStatus, 0 );
if( status != 1 && status != 2 && status != 3 ) {
throw "No movie open";
} else if (!BSPlayerWidgetLaunched){
//switch to MovieMode
SendMessage( bspwh, WM_BSP_CMD, BSP_MovieMode, 0 );
//launch BSPlayer Remote
theTerminal.ExecuteScript(BSPlayerUUID);
BSPlayerWidgetLaunched = true;
exit();
}
}
} catch( e ) {}

// Keep the keypad active
return true;
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group