简体   繁体   中英

How to play MP4 in wpf?

the most I managed so far was to reproduce the sound, without image

<MediaElement Name="myMediaElement" LoadedBehavior="Manual"
                          Margin="5"
                          Grid.Row="0"
                          Grid.Column="0"
                          ScrubbingEnabled="True"
                          Source="C:\Users\TheMagicTool Server\Downloads\myVideo.mp4"
                          />

Does the video show up at all? Just a hunch, try adding Height="200" Visibility="Visible" to the MediaElement.

<MediaElement Name="myMediaElement" LoadedBehavior="Manual"
                      Height="200" 
                      Visibility="Visible"
                      Margin="5"
                      Grid.Row="0"
                      Grid.Column="0"
                      ScrubbingEnabled="True"
                      Source="C:\Users\TheMagicTool Server\Downloads\myVideo.mp4"
                      />

Not sure if this'll help at all but worth a shot. MP4 should be supported.

According to the documentation the LoadedBehavior set to MediaState.Manual means that media will preroll but not play when the System.Windows.Controls.MediaElement is assigned valid media source . Therefore start from the minimal parameters set:

<Window ...
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    Title="MainWindow" Height="450" Width="800">
    <Grid>
        <MediaElement Source="C:\Users\TheMagicTool Server\Downloads\myVideo.mp4" />
    </Grid>
</Window>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM