sinloong
asked on
Windows Media Player 9 in a Multi-threaded Class
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.AxWindowsMediaPla yer()
but the following error occured:-
Run-time exception thrown : System.Threading.ThreadSta teExceptio n - Could not instantiate ActiveX control '6bf52a52-394a-11d3-b153-0 0c04f79faa 6' 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.OpenPlaye r("c:\MTV. dat")
Please help, thanks.
I tried to create an instance of the Windows Media Player ActiveX control in my class as below,
m_objMediaPlayer = New AxWMPLib.AxWindowsMediaPla
but the following error occured:-
Run-time exception thrown : System.Threading.ThreadSta
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.OpenPlaye
Please help, thanks.
ASKER
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.AxWindowsMediaPla yer()
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.AxWindowsMediaPla
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Apart
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.