One, create a new Windows Application project, add the Vedioform form
Second, locate Windows Media Player in the COM component and add a reference
Three, the code is as follows:
1 Public Partial classVedioform:form2 { 3 PrivateAxwmplib.axwindowsmediaplayer AxWindowsMediaPlayer1; 4 PublicVedioform ()5 { 6 InitializeComponent (); 7 Initvedio (); 8 } 9 Private voidVedioform_load (Objectsender, EventArgs e)Ten { One Initvediourl (); A initevent (); - } - //initializing the playback controls the Private voidInitvedio () - { - This. AxWindowsMediaPlayer1 =NewAxwmplib.axwindowsmediaplayer (); - This. axwindowsmediaplayer1.enabled =true; + This. axwindowsmediaplayer1.location =NewSystem.Drawing.Point (0, -); - This. Axwindowsmediaplayer1.name ="AxWindowsMediaPlayer1"; + This. axwindowsmediaplayer1.size =NewSystem.Drawing.Size ( -, -); A This. Axwindowsmediaplayer1.tabindex =2; at This. Controls.Add ( This. AxWindowsMediaPlayer1); - } - //Initialize the video file address of the playback control - protected voidInitvediourl () - { - This. Axwindowsmediaplayer1.url =@"d:/vedio/default.wmv"; in } - to + protected voidinitevent () - { theAxwindowsmediaplayer1.statuschange + =NewEventHandler (Axwindowsmediaplayer1_statuschange); * } $ Panax Notoginseng //video loop playback via control state change - protected voidAxwindowsmediaplayer1_statuschange (Objectsender, EventArgs e) the { + /*0 Undefined Windows Media Player is a Undefined state. (Not defined) A 1 Stopped Playback of the current media item is Stopped. (stop) the 2 Paused Playback of the current media item is Paused. When a media item was paused, resuming playback begins from the same location. (stay) + 3 Playing The current media item is Playing. (play) - 4 Scanforward The current media item is fast forwarding. $ 5 Scanreverse The current media item is fast rewinding. $ 6 Buffering The current media item was getting additional data from the server. (conversion) - 7 Waiting Connection is established, and the server is not sending data. Waiting for session to begin. (suspended) - 8 mediaended Media item has completed playback. (end of play) the 9 Transitioning Preparing New media item. - Ten ready to begin playing. (Ready)Wuyi reconnecting reconnecting to stream. (reconnect) the */ - //determine if the video has stopped playing Wu if((int) Axwindowsmediaplayer1.playstate = =1) - { About //pause for 2 seconds and replay again $System.Threading.Thread.Sleep ( -); - //re-play - AxWindowsMediaPlayer1.Ctlcontrols.play (); - } A } +}
[Basic Properties]
Url:string can specify media location
Enablecontextmenu:boolean Display/Do not display the right-click menu for playback position
Fullscreen:boolean Full Screen display
Stretchtofit:boolean whether to stretch to optimal size when not in full-screen state
Umode:string player mode, full: The following control bar; None: Only the playback section has no control bar
Playstate:integer the current control state, the OnStatusChange event is triggered when the state changes
[Controls]
The player can be controlled by windowsmediaplayer.controls and some related information is obtained:
Controls.play; Play
Controls.stop; Stop it
Controls.pause; Time out
Controls.currentPosition:Double Current Playback Progress
Controls.currentPositionString:string the time-format string "0:32″
[Currentmedia]
Can get information about the current media through Windowsmediaplayer.currentmedia
Currentmedia.duration Double Total length
Currentmedia.durationstring the time-format string "4:34″
[Settings]
The player can be set by windowsmediaplayer.settings, including volume and channel.
Settings.volume:integer Volume (0-100)
The Settings.balance:integer channel, through which it should be able to control the stereo, left channel, right channel.
Media player player.playstate get playback status Events
Value State Description
0 Undefined Windows Media Player is a Undefined state. (Not defined)
1 Stopped Playback of the current media item is Stopped. Stop
2 Paused Playback of the current media item is Paused. When a media item was paused, resuming playback begins from the same location. Stay
3 Playing The current media item is Playing. Player
4 Scanforward The current media item is fast forwarding.
5 Scanreverse The current media item is fast rewinding.
6 buffering The current media item was getting additional data from the server. Convert
7 Waiting Connection is established, and the server is not sending data. Waiting for session to begin. Pause
8 mediaended Media item has completed playback. (End of play)
9 Transitioning Preparing New media item.
Ten ready to begin playing. (Ready)
Reconnecting reconnecting to stream. (reconnect)
Original: Http://blog.csdn.net/slimboy123/archive/2010/06/23/5688616.aspx
Windows Media Player plays video