?
Solved

Windows Media Player 9 in a Multi-threaded Class

Posted on 2003-02-24
4
Medium Priority
?
373 Views
Last Modified: 2007-12-19
Does anyone knows how to launch a Windows Media Player 9 control (to play a movie file) from a Multi-threaded class?

I tried to create an instance of the Windows Media Player ActiveX control in my class as below,

m_objMediaPlayer = New AxWMPLib.AxWindowsMediaPlayer()

but the following error occured:-

Run-time exception thrown : System.Threading.ThreadStateException - Could not instantiate ActiveX control '6bf52a52-394a-11d3-b153-00c04f79faa6' because the current thread is not in a single-threaded apartment.

I have tried the following method too, the Media Player control is displayed and the movie is playing, but I can't get the PlayState and Open State of the Media Player control :-

m_objMediaPlayer = New WMPLib.WindowsMediaPlayer()
m_objMediaPlayer.OpenPlayer("c:\MTV.dat")

Please help, thanks.
0
Comment
Question by:sinloong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8008180
ASP.Net threads are MTA by default. So you can't instatiate a single threaded controls or components without changing the threading model to STA or Aparemtent threaded. There are 2 ways to do it.

1. in your page attribute, set aspCompat to "true".
2. You can setthe same attribute programtically in your page's Init module.
 Page.AspCompat = true
3. or you can change the current thread's ApartmentState to STA.

Thread.CurrentThread.ApartmentState = ApartmentState.SAT

For windows apps, you will have to make sure that main function has STA attribute set for apartment type or right at the begining of app you can change the threading mode.
0
 

Author Comment

by:sinloong
ID: 8022549
Thanks naveenkohli, FYI, I am doing this for windows application in VB.NET, not ASP.NET.

I have set the apartment type to single threaded attribute right at the begining of my component, but it didn't work. I am still getting the same error message when calling the following code :-

m_objMediaPlayer = New AxWMPLib.AxWindowsMediaPlayer()
0
 

Author Comment

by:sinloong
ID: 8290274
nvm, I have found my problem, I have to create another new thread to make sure that the thread is in a thread safe fashion.
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 2000 total points
ID: 8662142
COuld you please take care of this open question so that it can be moved to PAQ?

Thanks.
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

800 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