Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Media Player Exception in Windows Application 1

Status
Not open for further replies.

drkarr

IS-IT--Management
Aug 10, 2005
24
US
I have written a VB.net program that uses Windows Media Player to play very short .wav files at appropriate places. The default name of the player has been changed to "Player" and this has not been a problem with other programs. The problem now is that when I call the program I get an exception (resulting in a program break) in the following line of the automatically generated code:

CType(Me.Player, System.ComponentModel.ISupportInitialize).EndInit()

The above is copied from the automatic code so should be correct, but why is the program breaking there?

Thanks,
DRK
 
Here is the debugger message associated with the above issue:

Additional information: Exception from HRESULT: 0x80040200.

A first chance exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: The source object does not expose 'IPropertyNotifySink' event interface.

The program '[2008] M2S.exe' has exited with code 0 (0x0).
 
Still have this problem with trying to use Windows Media Player in a VB.net program. Here is the message I get when I load the form with the player:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in system.windows.forms.dll

Additional information: Exception from HRESULT: 0x80040200.

Would appreciate help. Thanks. DRK
 
check if there is an inner exception on the exception that was thrown. Often COM/OLE errors get wrapped up in a generic COMException or OLEException, but the important info is in the exception.innerexception member.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks Rick. Can you be more specific about how to check for "the exception.innerexception member?" If I locate the appropriate info, will it be adequate to allow me to fix it or do I need more?

DRK
 
where ever you are catching the existing exception.
Code:
try
  'code that throws the exception
catch COMexc as COMException
  debug.writeline comexc.message
  if not comexc.innerexception is nothing then _
    debug.writeline comexc.innerexception.message
end try

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick,

Here is the automatic code that throws the exception:

CType(Me.Player, System.ComponentModel.ISupportInitialize).EndInit()

1. Is the following code to be inserted in its place?

try
'code that throws the exception
CType(Me.Player, System.ComponentModel.ISupportInitialize).EndInit()
catch COMexc as COMException
debug.writeline comexc.message
if not comexc.innerexception is nothing then _
debug.writeline comexc.innerexception.message
end try

2. I get a "COMException not defined" error when I try this. Declaring COMException didn't help. Suggestions?

DRK
 
Hey Rick,

I will be happy to pay for your time if you could look at the program and find a fix.

Don
 
try just cantching a general Exception. Typing your catch blocks is only useful if you are expecting different types of exceptions and want to handle them differently. In this case, we're just trying to find out what's wrong, so just use Catch exc as Exception.

As for why you can use ComException, it's likely in some namespace that you don't have included. If you catch it as an exception, you should be able to look at the exception object's type (in the cmd window: gettype(exc)) and that should give you COMException's full name.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I've tested Windows Media Player using both the ActiveX control as you have done and by directly referencing the library as in these two buttons.

Code:
  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    Dim wmp As New WMPLib.WindowsMediaPlayer
    wmp.URL = "C:\Documents and Settings\All Users\Documents\My Music\Sample Music\Beethoven's Symphony No. 9 (Scherzo).wma"


  End Sub

  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

    Player.URL = "C:\Documents and Settings\All Users\Documents\My Music\Sample Music\Beethoven's Symphony No. 9 (Scherzo).wma"

  End Sub

I renamed my ActiveX control Player as you can see.

Both work fine. However the line on which you report the error is the final line of the Form creation process. Are you doing something else in that Region that might be causing the problem.

Additionally, if you want to use a Try / Catchblock, I would place it here:

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Try
..
..
..
Me.ResumeLayout(False)
Catch ex As Exception
'Report the error here
End Try

Where you were placing the error trap was immediately around the highlighted line, but something else may have cause the problem.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top