locked
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 
    wmp.ctlcontrols.play() 

    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?

    Thanks
    Sunday, June 29, 2008 7:52 PM

Answers

  • 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" 
        wmp1.controls.play()  
        MessageBox.Show(wmp1.currentMedia.duration.ToString())  
     


    By the way, this code sample may be helpful to you.
    How to count down the media playing duration
    http://forums.microsoft.com:80/MSDN/ShowPost.aspx?PostID=2820726&SiteID=1


    Regards,
    Martin
    Friday, July 4, 2008 12:37 PM