Play videos such as "dotnet,c#" in WinForm

Source: Internet
Author: User
Tags dotnet

The problem with the project is how to play the video in WinForm. There were several ways of looking at it, the first being to use the Windows Media Player component directly, and the second was to use DirectX to draw directly on a form or control, which is more complex. So the first method is used.

First add the Windows Media Player component from the VS Toolbox by opening the Toolbox, right-clicking in the bottom margin, selecting an item, and then switching to the COM Component tab in the Popup dialog box, locating the Windows Media Player entry and selecting When you're sure, you'll see an extra icon in the Toolbox, and then you can drag the icon onto the form to set it up.

The main point here is that when you set up the Windows Media Player component, there is a property of "no window playback", and if it is not enabled, the video will switch to full screen if you click the mouse at the time of video playback, and the activation will not occur. But if enabled, the sharpness of the video will drop a lot (the grainy sense becomes obvious), not enabling mouse clicks will enlarge. At first I used timing to change the full-screen property to False to achieve, the clock is set to 100 milliseconds or less, the display is the user double-click the video, shielding suddenly a bit bigger then back to the same, More dangerous is that this operation has a certain probability (and not low) will be exposed to the XP taskbar (because our terminal is to display full screen, not let the user see the desktop and other actions), so I repeated testing, the final adoption of another way, that is, filtering form events to directly block the video area of mouse messages. The specific implementation is as follows:

Define a message Filter class to block the mouse double-click on the specified area or click the message. You can then load this filter in your application to implement the masking message feature.

1  Public classMessagefiltermgr:imessagefilter2 { 3 Rectangle Rect;4      Publicmessagefiltermgr (Rectangle rect)5     { 6Rect =rect;7     }8 9      Public voidStart ()Ten     {  OneApplication.addmessagefilter ( This);  A     } -  -      Public voidStop () the     {  -Application.removemessagefilter ( This);  -     } -  +      Public BOOLPrefiltermessage (refSystem.Windows.Forms.Message SystemMessage) -     {  +         if(Systemmessage.msg >=513&& systemmessage.msg <=515)//513|515 is the value of the corresponding target message A         {  at             if(Control.mouseposition.y > Rect.y && control.mouseposition.y < Rect.y +Rect.height -&& control.mouseposition.x > Rect.x && control.mouseposition.x < Rect.x +rect.width) -             {  -                 return true;  -             }  -         }  in         return false;//the response is False -     }  to}

Mouse click problem has been solved, and now the last problem, is how to achieve video continuous playback function. I started using the window Media Player's state Change event to control, that is, when the state of the player changes, found that it is a stop state, immediately send the instructions to play the next video, this method of control is cumbersome, the video pause time is a bit long (about 0.4 seconds of appearance). Instead, use a playlist to directly define the playlist so that it automatically loops back. The implementation is as follows:

1  This. Player.settings.setMode ("Loop",true);//set Playlist to loop play2 foreach(stringIteminch  This. Videos)3 { 4        This. Player.currentPlaylist.appendItem ( This. Player.newmedia (item));//add video to a playlist individually5}

Finally, our terminal also realizes the video and the picture mix to play the function, namely after the video has finished to play the picture again, I will realize the way to summarize as follows:

Cancels playback of the playlist at startup;

Continue to use the status of the playback component to change events, when the player's status is Wmppsready (when the number of videos in the playlist is greater than 1 o'clock) or wmppsstopped (when there is only one video in the playlist), indicates that playback is complete, and then hides the playback component, And then enable the picture automatically switch program, and so on after the picture switch, then the playback component display, enable playback.

Also, by default, Windows Media Player supports a limited number of video formats (best choice is WMV) and wants to support more video formats, only by installing a video decoder.

Play videos such as "dotnet,c#" in WinForm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.