[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.




6 comments

May I know how did you get that components ? I already Install the MPC but I don't see that components on the choose TOOLBOX ITEMS ? hoping for your reply ...

Reply

Hai Carl ,

sorry for late reply (too much event here :D), the component i use on that tutorial above is K-LITE.
i deploy on WIN XP (old OS :( ).
so if you want to develope application use win 7 + or later i suggest you using standar media player (don't use third party, too much conflict when you distribute another machine).

you can use this tutorial : http://mynotework.blogspot.com/2015/03/vbnet-windows-media-player.html

becareful, the name of the component K-Lite with Windows media player is same, the different is from the path.

Reply

hello sorry for my reply also , thank you for your reply, for me its okay I will install again the k-light if i distribute the application , but did you try use win7OS while developing , i used to install k-light but i don't see that DLL for this application, any idea for this ?

one another thing if i use WMP built in application , doesn't support my need , I want to use the option in rendering Frame the (STRETCH TO WINDOW) option for the k-light and MPC-HC , WMP doesn't have this ?

or do you have idea to do this option on WMP , stretch to fit is not my answer I want STRETCH TO WINDOW any video I played ? thanks, hoping for your reply ...

Reply

Hai Carl ,

i don't know compatibility of K-lite in win 7 , first i tried develop App use K-Lite in XP but when i distribute in the App in win 7. it has a problem, the video not show (just blank) until know i don't know the solution of this. but if you develop app to distibute to another machine i suggest u using standart wmp from windows. of course between K-Lite and WMP support STRETCH TO WINDOWS. so if you have a video but low resolution for exampe you have video with resolution 320 x 150 but your WMP control 720 x 640 and yes your video will be full screen follow the frame size but you know the quality will be break. it's different if you have high resolutin for example your video 1900 x 1280 and your WMP control 720 x 640, of course it will fit to your control and the quality still same BUT it will take long buffering because of the size of video. so i hope if you can make video resolution same as you control object. for the code you check on google, it's everywhere :D

Reply

okay thank you for your reply ...

Reply

Post a Comment

Harap gunakan bahasa yang baik dan sopan, terima kasih