Link to home
Start Free TrialLog in
Avatar of JustinWillis
JustinWillis

asked on

Don't winexec while video playing

Hello, I have a product which runs an update program every 3 hours or so to keep definitions up to date, not anti virus prog but along those lines.. Sorry for the long explanation but neccessary i think...

Anyway, all is well but I noticed that if I winexec the updater.exe while a video is playing in Windows Media Player etc it interupts full screen playback and no doubt annoys my users when this occurs (it annoyed me the other day when watching a dvd ;), I have seen other programs (like screen savers) avoid execution when there is video playback happening, the pc is idle but it is clever enough to know that the user may be just watching something!

I am looking for something like...

var PlayingVideo: boolean;
If PlayingVideo = false then winexec('updater.exe',sw_show);

I just need to find a way to detect video playback and set PlayingVideo (dvd or the odd avi, mpeg etc.. and other players other than media player would also be great but probably asking too much!)

Thanks in advance for you help, I hope this makes sense, I'm sure you will tell me if it does not ;)

Oh btw I would like the updater to be visible when run so something like changing to sw_hide is not what I'm after, I want the user to know that an update is happening, I would rather skip or postpone the update for when video playback has stopped.

Regards,
Justin Willis.
SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
h := FindWindow(nil, 'Windows Media Player');
will return a handle h if it finds it.
So if you set h := nil to start with, you can check to see if it is still nil after doing the FindWindow.
If it is nil then you know that the current PC does not have WMP running.

Im not very well versed in the windows API calls, so if I made a mistake Im sure someone will point it out.
ok slight mistake, you cant set h to nil. My bad, like I said I try and stay away from pointers and handles if I possibly can.
After a quick test it seems that if the FindWindow does not find WPM the handle value gets set to 0.

I just did

h := Application.Handle;  // so that the value of h is not 0 to start with
h := FindWindow(nil, 'Windows Media Player');  // h set to 0 if doesnt find WPM otherwise it is a +ve number

Is this of any use?
Avatar of JustinWillis
JustinWillis

ASKER

Sorry for delayed response, I thought of using this method but if the user has music playing or has just left WMP open then the update program would hardly ever run, was a good idea but doesn't really solve the problem, it's only video playback im really trying to detect, if no one else can solve in the next few days then the points are yours anyway but I have a feeling there is some way of doing this properly.

Thinking about it a bit more I guess just knowing when WMP is in full screen mode would be partly sufficient, although I was hoping to support all players (basically dvd players), I am hoping that there is something in the windows API which can tell an app if there is video content playing, I don't think screensavers kick in when this is the case, not sure how they do it.

Justin.
Well maybe in conjunction with FindWindow, if you get a correct handle to WMP, you could then try and get the handle for the caption of the file name on the form itself and maybe check to see if the file extension is of a video type and not something else. Unfortunately I don't know how to get a list of components on the form through the API calls though I have seen a lot of examples recently that you might be able to search through.

Good luck
Cheers Mike, i'll toy with your idea to try and get it to work, If i manage it this way then the points are yours otherwise will leave this open for a few days but will make sure you get an assisted answer at least for your efforts.

Thanks,
Justin.
Glad I could at least give some help.
Ill watch this thread myself too to see if someone comes up with a solution I can note down for future use.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your input smot but Mike already came up with that one, doesn't really solve my problem, see post at 2:26PM

Thanks anyway though ;)

Just.
hmm I have noticed that Windows Media Player itself has the "Allow screen saver during playback" option, so it is not the screen saver or windows itself being intellegent about playback detection, it's WMP stopping screen savers which makes it seem more likely that it can't be done as easily as i had hoped.

I will settle for the detection of WMP for now, and maybe post another question later about how to detect if it is in Full Screen mode, as I know some people just leave their players open idle which would really mess up my updating but I think this is prefered over it annoying people trying to settle down for a film and chill..

Thanks again for your help guys, although it was Mike's idea, smot did provide working implementation too so will split points based on effort, hope this is cool...

Just.