Use AxWindowsMediaPlayer From Within Class LIbrary RRS feed

  • Question

  • Hi,

    I need to create a class that is able to get the duration for MPEG2 and MPEG4 files. The best and easiest way I saw was to use WMPLIB. I am able to get the duration for the files but only when I start playing the file. So I chose to integrate that in a DLL. However, it seems that the control does not work normally unless from within Windows Forms. It doesn't initialize properly if I declare it by code rather than from the toolbox. Here is the code I tried:

    Friend WithEvents wmp As AxWMPLib.AxWindowsMediaPlayer 
    wmp.url="c:\file.mpg"   '=>Error occurs here 

    My question, how can I make use of WMPLIB from within a Class library without problems. Is there a better way to get the duration of MPEG files?

    Sunday, June 29, 2008 7:52 PM


  • Hi Leedo,

    Project menu -> Add Reference -> Com tab -> Windows Media Player
    (Reference path is C:\windows\system32\wmp.dll)
        Friend WithEvents wmp1 As New WMPLib.WindowsMediaPlayer  
        wmp1.URL = "c:\file.mpg" 

    By the way, this code sample may be helpful to you.
    How to count down the media playing duration

    Friday, July 4, 2008 12:37 PM