By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,262 Members | 2,664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,262 IT Pros & Developers. It's quick & easy.

Need to launch event after form load

P: n/a
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

Jan 23 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,
You could use a timer and then have the Tick event update the label
after a second or so.

HTH,
James.

Ronald S. Cook wrote:
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
Jan 23 '07 #2

P: n/a
Hi,

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

| 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?
--
Ignacio Machin
machin AT laceupsolutions com
Jan 23 '07 #3

P: n/a
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);
--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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

Jan 23 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.