Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Don't winexec while video playing

Posted on 2005-04-11
11
Medium Priority
?
375 Views
Last Modified: 2010-04-05
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.
0
Comment
Question by:JustinWillis
  • 6
  • 4
11 Comments
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 600 total points
ID: 13752212
One possible solution might be to check to see if there is an active window called "Windows Media Player" using then FindWindow method. This way regardless of what is file is playing you can at least check to see if WMP is running or not.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13752281
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.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13752297
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13752328
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?
0
 
LVL 1

Author Comment

by:JustinWillis
ID: 13752492
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.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13752578
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
0
 
LVL 1

Author Comment

by:JustinWillis
ID: 13752613
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.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13752770
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.
0
 
LVL 3

Accepted Solution

by:
smot earned 400 total points
ID: 13753322
var
  wnd: HWND;
begin
  wnd := FindWindow('WMPlayerApp',nil);
  if wnd = 0 then // Mediaplayer not found...
  begin
    // start download....
 end;
end.
0
 
LVL 1

Author Comment

by:JustinWillis
ID: 13753771
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.
0
 
LVL 1

Author Comment

by:JustinWillis
ID: 13755067
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question