Need to launch event after form load

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

In my Win app, I'm needing to load a media file into my Windows Media Player
control, and THEN read an attribute from the file.

The thing is, the file has to be playing for a split second before the
attribute can be read.

I can have wmpPlayer.URL = @"D:\Web\FWT\TestFile.wma"; in my form load event
and then a button on the form to get the value I need...

label1.Text = wmpPlayer.currentMedia.getItemInfo("Abstract");

But I don't want to have to manually click a button. I want the form to
load, start playing the file, and then somehow trigger an event to go and
get the attribute.

Thanks for any help.
Ron
 
Hi,
You could use a timer and then have the Tick event update the label
after a second or so.

HTH,
James.
 
Hi,


| But I don't want to have to manually click a button. I want the form to
| load, start playing the file, and then somehow trigger an event to go and
| get the attribute.

A timer?
 
Hi Ron,

After you start the player, try calling System.Threading.Thread.Sleep(500),
but with the desired wait time in milliseconds (my example is 1/2 second).
Then you can retrieve the attribute.

If the player is running on the executing thread than you'll have to wait
asynchronously. Maybe a bit convoluted, but here's one solution:

// 2.0 framework syntax

System.Threading.SynchronizationContext context =
System.Threading.SynchronizationContext.Current;

MethodInvoker invoker = new MethodInvoker(delegate()
{
// this code will run asynchronously
System.Threading.Thread.Sleep(500);

context.Send(delegate(object state)
{
// this code will run on the main UI thread
// TODO: retrieve value
}, null);
});

// TODO: start player

invoker.BeginInvoke(delegate(IAsyncResult result)
{
invoker.EndInvoke(result);
}, null);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top