[VB.NET] Windows Media Player Classic


Description
      this tutorial i will show how to add windows media player Classic into the form (vb.net), and get the source of media , and how to repeat forever the player.


HowTo
     1. Open your project VB.NET , click on the toolbox icon on the left, after the toolbox appeared right click on the area of toolbox and click choose item.



     2. Select COM Component and choose "Windows Media Player"



     3. A new item will appear in the toolbox, now drag it to the form and give name myplayer. Until now you success add player to the form. now we need the path of source the media for example zzz.wmv and location in the D:\.

     4. to add path just add this code in the form load : 
      myplayer.FileName = "D:\zzz.wmv"
       myplayer.play()
      if you have dynamic path maybe you can use this : 
      myplayer.FileName = My.Application.Info.DirectoryPath & "zzz.wmv"
      myplayer.play()

     5. Now Run it, the video will be playing :), but some case we need playing repeatly forever. just right click the object of myplayer, and choose "Properties". it will appear the properties media player, now select "Repeat Forever" and click ok. 



     6. Done, you video will play forever.


*Another property :

       - ShowControl => display/hide control on wmp.
       - CurrentPosition => current position of trackbar.

       - Duration => Get the duration of file (will be show after play())
       - PlayState => Check state of the control (mpStopped/mpPlaying/mpPause)

* get position track (you can add to trackbar control)

trackBar.Maximum = myplayer.Duration
trackBar.Value = Math.Floor(myplayer.CurrentPosition)
lblStatusTrack.Text = ("Time Elapse : " + convertSecondsToTime(Math.Floor(myplayer.CurrentPosition)) + " from " + convertSecondsToTime(Math.Floor(myplayer.Duration)))


* Windows media player classic best docking on form !!, you can control the size of WMP Classic. to make fullscreen just adjust the form and windows media player classic to maximize
       form1.WindowState = FormWindowState.Maximized
       form1.myplayer.DisplaySize = MediaPlayer.MPDisplaySizeConstants.mpFullScreen

*Found the solution "blank" problem when distribute to another machine :
      - the problem : wrong setting property item (object property) in windows media player classic (K-LITE). here's the correct setting :
        AllowChangeDIsplaySize : TRUE
        AutoStart : TRUE
        DisplayMode : Mptime
        DisplaySize : MpFitToSize
        WindowslessVideo : False

to distribute to another machine just install K-LITE, and before compile don't forget to copy local all external library. this video can play many format including .mov files.