WPF The video support is also based on Mediaplayer Class and Its Related Mediaelement And Mediatimeline . Because Mediaplayer Is based on Windows Media Player 10 Or a later version, as long Windows Media Player Formats of videos that can be played (for example . Wmv,. Avi,. mpg ), In Mediaplayer Or Mediaelement Can be played in all (the premise is that the system must be installed Windows Media Player 10 Or higher ).
WPF The playing of the video in is similar to that of the audio (in use Mediaelement By setting Source The attribute is a video file. If you use Mediaplayer Because the video needs to be displayed in a window during playback Mediaplayer YesProgramCodeDesigned (not involved UI Display), to display Mediaplayer The loaded media must be used. Videodrawing Or Drawingcontext (In ( 2 ).
UseMediaelementThe code for playing a video is as follows:
<Grid>
<Mediaelement source = "C:" users "public" videos "sample Videos" bear. wmv "opacity =" 0.5 ">
<Mediaelement. Clip>
<Ellipsegeometry center = "220 220" radiusx = "220" radiusy = "220"/>
</Mediaelement. Clip>
<Mediaelement. layouttransform>
<Rotatetransform angle = "180"/>
</Mediaelement. layouttransform>
</Mediaelement>
<Mediaelement source = "C:" users "public" videos "sample Videos" bear. wmv "opacity =" 0.5 ">
<Mediaelement. Clip>
<Ellipsegeometry center = "220 220" radiusx = "220" radiusy = "220"/>
</Mediaelement. Clip>
</Mediaelement>
</GRID>
Use twoMediaelementPlay the same video file.180Degrees of rotation, as shown in:
To control video playback, you canMediatimelineUsed in combinationPausestoryboard,ResumestoryboadAnd other actions.
One issue that requires attention is that media files cannot be embedded resources.MediaplayerIt can be understood that the path is an absolute path, a relative file path, orURL.