Audio but no video when playing a movie using mediaplayerelement in wpf - c#

I am trying to use MediaPlayerElement in a WPF to play streaming videos. I have set up a simple WPF window that contains a MediaPlayerElement instance and auto-plays a video. When I run the program, I can hear audio but the video is not visible.
I started by following this tutorial:
https://learn.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/mediaplayerelement
Unfortunately the tutorial appears to be out of date, as it no longer works. I made a few corrections to get it to a running state, but cannot get the video to appear.
I have tried placing the MediaPlayerElement inside a Grid or StackPanel, but can't because it is not a UIElement.
<Window x:Class="MediaPlayerElement_Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MediaPlayerElement_Test"
xmlns:controls="clr-namespace:Microsoft.Toolkit.Forms.UI.Controls;assembly=Microsoft.Toolkit.Forms.UI.Controls"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<controls:MediaPlayerElement Name="mediaPlayerElement" AutoScaleDimensions="800,450"
Source="https://mediaplatstorage1.blob.core.windows.net/windows-universal-samples-media/elephantsdream-clip-h264_sd-aac_eng-aac_spa-aac_eng_commentary-srt_eng-srt_por-srt_swe.mkv"
AutoPlay="True" Anchor="Top" Height="450" Width="800" AreTransportControlsEnabled="True" />
</Window>
Does anyone know what I am doing wrong here? How do I get the video to display in the window?

Try this one, this works perfectly for me
<Window x:Class="Test.Media"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
Title="Media" Height="450" Width="800">
<Grid>
<MediaElement Margin="10,10,10,0 " Source="http://mediaplatstorage1.blob.core.windows.net/windows-universal-samples-media/elephantsdream-clip-h264_sd-aac_eng-aac_spa-aac_eng_commentary-srt_eng-srt_por-srt_swe.mkv"
Name="McMediaElement"
Width="450" Height="250" LoadedBehavior="Play" UnloadedBehavior="Stop" Stretch="Fill"/>
</Grid>
if this is not working then it might be the issue with your video codec

Related

C# WPF | Is There A Way To Play UHD Video In MediaElement?

I recently trying to play a video in 4k (3840x2160) that i've downloaded from YouTube in a Media Element. But problem, nothing appears !!
The same video with the same codec in HD (1920x1080) play perfectly !!
Is there a way to play the video in 4k ? (I tried some nuget packages but it doesn't work either)
PS: Media Element is not obliged !
Code :
<Window x:Class="VideoPlay.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VideoPlay"
mc:Ignorable="d"
Title="MainWindow" Background="#181818" WindowState="Maximized" WindowStartupLocation="CenterScreen">
<Grid>
<MediaElement Height="800" Width="Auto" Stretch="Uniform" Source="C:\Users\Utilisateur\Downloads\COSTA RICA 4K HDR 60FPS.webm" LoadedBehavior="Play"/>
</Grid>
</Window>

Zoombox from Xceed WPF Toolkit not working

I am experimenting with the Zoombox control from Xceed, but I am having trouble getting it to respond to mouse wheel or pan events. Nothing happens when I use these inputs. Am I missing something in my code or configuration?
https://github.com/xceedsoftware/wpftoolkit
<Window x:Class="UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="700">
<Grid>
<xctk:Zoombox MinScale="0.5" MaxScale="100" >
<Grid Width="600" Height="400" Background="Yellow">
<Ellipse Fill="Blue" />
</Grid>
</xctk:Zoombox>
</Grid>
</Window>
You have to define DragModifiers and ZoomModifiers. Default values are Ctrl and Shift keys. So use the combination Shift+MouseWheel for zooming and use Ctrl+LeftButton for panning.

Media element not support in WPF Page

I want to display a progress bar in WPF Page,when it loaded. I used media element to display a gif image. Below code describe what I did.
<Page x:Class="WpfApplication3.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1" Loaded="Page_Loaded">
<Grid>
<MediaElement Grid.Column="2" Grid.Row="4" Margin="0,0,47,0" HorizontalAlignment="Right" Width="80" Source="progress.gif" LoadedBehavior="Manual" Name="MP"/>
</Grid>
</Page>
private void Page_Loaded(object sender, RoutedEventArgs e)
{
MP.Play();
}
but this progress bar not showing in Page
How can I fix this.
(when I tried with progress bar also, got same problm)
(It works ok in window )
You could use the WpfAnimatedGif library to easily display an animated gif using a simple Image element:
How do I get an animated gif to work in WPF?
Just download the package from NuGet: https://www.nuget.org/packages/WpfAnimatedGif
And set the ImageBehavior.AnimatedSource attached property of the Image element:
<Page x:Class="WpfApplication3.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="Page1"
<Grid>
<Image gif:ImageBehavior.AnimatedSource="progress.gif" />
</Grid>
</Page>

WPF Image with Remote Path

I am trying to load an image into my Silverlight project and I have the following XAML:
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
<Grid x:Name="LayoutRoot" Background="White">
<Image Height="150" Width="200" Source="http://wsf.cdyne.com/WeatherWS/Images/rain.gif" />
</Grid>
</UserControl>
The Image control in Silverlight only supports PNG and JPEG, not GIF.
http://msdn.microsoft.com/en-us/library/system.windows.controls.image(VS.95).aspx

Looking to find how to add resize button

Hello:
I have been experimenting with WPF this afternoon, Im wondering does anyone know how I can manually enable resizing ? I have my main windows set with the following properties which removes the close/min/max and resize;
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" AllowsTransparency="True"
WindowStyle="None" Background="Maroon" ResizeMode="CanResize">
</Window>
I have found how to add my own close/min/max buttons but have not found how to enable resizing.
ResizeMode="CanResizeWithGrip"

Categories

Resources