I am making a video game in C# WPF. I have a huge number of MediaElements, that run mp3 and mp4 files when needed. Recently I read that there is a license fee for just using those file formats, and decided to convert them to ogg and ogv formats.
Just to be sure you understand: I am not trying to make my own video player. I only need a way to run relevant files, at the correct stages of my game.
I found some information on the web, and now trying to make a small test app, that just runs a video on start.
I installed those NuGet plugins (didn't know which one is needed):
Meta.Vlc, Vlc.DotNet.Core, Vlc.DotNet.Core.Interops, Vlc.DotNet.Wpf
That's my xaml file:
<Window x:Class="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:wpf="clr-namespace:Vlc.DotNet.Wpf;assembly=Vlc.DotNet.Wpf"
xmlns:local="clr-namespace:Test"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>
<MediaElement x:Name="movTest" Panel.ZIndex="1" HorizontalAlignment="Left" Height="319" Margin="10,0,0,0" VerticalAlignment="Top" Width="507" LoadedBehavior="Manual" Source="Resources/VideoFallingFromTable.ogv"/>
<wpf:VlcControl x:Name="movTest2" Panel.ZIndex="2" />
</Grid>
Now, I see that there is no "Source" for wpf:VlcControl.
Si, I tried to load the source from MediaElement.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
movTest2.MediaPlayer.Play(movTest.Source);
}
But I get just black window and no sound. I guess I am doing something wrong.
Can you help me learn to run VLC player in WPF?
Thank you,
Evgenie
UPDATE:
I tried following code:
VlcControl thisVlcControl = new VlcControl();
Uri src = new Uri(movTest.Source.ToString(), UriKind.RelativeOrAbsolute);
thisVlcControl.MediaPlayer.Play(src);
For some reason, it worked with mp4 file, but not with ogv.
Related
Yesterday I create a project in my disk D partition and I found the images I put into project can't be displayed well. XAML code below is very simple:
<Window x:Class="WpfImageTest.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:WpfImageTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Image Width="300" Height="300" Source="/Resources/Images/Chen.png"/>
</Grid>
</Window>
You can see I write a relative path for Image control's Source property and when I run the application it shows nothing on the interface.But magically I copy all the files into the root of my C partition or D partition of my physical disk and rebuild the project, the application runs properly. This proplem troubles me almost all day , can anyone explain why this thing happens?
The original location of my project is D:\Programming\C#\Practice\WpfImageTest and I have already set all images build property to Copy all the time and Content.
Select your image file in your Solution Browser and set its Build Action to Resource as on image below.
I'm sorry if this comes off as a rookie question, but I have spent more time on this than I care to admit.
I'm trying to have a video autoplay on the program's startup. The main window preview shows that the video has been found; however, when I start the program I get a white screen. If someone could help me that would be much appreciated. Thank you and have a wonderful day!
Below is the entirety of the program's xaml code. I have tried running it in other builds of visual studios with no success - so I don't think it's vs.
<Window x:Class="SUP.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:SUP"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<MediaElement Name="VidPlayer" HorizontalAlignment="Left" Height="321" VerticalAlignment="Top" Width="518" Source="Videos\Vid.mp4" LoadedBehavior="Play"></MediaElement>
</Grid>
</Window>
Make sure your video file has Copy To Ouput Directory set to Copy always or Copy if newer.
I am trying to play videos through multiple MediaElement controls. However, when playing two H.265 side by side, only one (or sometimes none) of them plays. However, two H.264 videos play side by side perfectly fine. The necessary codecs to play the H.265 video are already installed, and the videos play fine with Windows Media Player.
Here is a very simple example to demonstrate my problem:
XAML:
<Window x:Class="Wpf.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:Wpf.Test"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<MediaElement Name="video_1" Source="C:\Users\public\Videos\test_vid_1.mp4" LoadedBehavior="Play" />
<MediaElement Name="video_2" Source="C:\Users\public\Videos\test_vid_2.mp4" LoadedBehavior="Play" Grid.Column="1" />
</Grid>
</Window>
This problem doesn't exist only when the videos are attempted to be played at the same time. It still persists when I try to play one video after the other (still using the different MediaElements). Any help with this is greatly appreciated.
Try turning off hardware acceleration in that window.
I found this to solve a problem very similar to yours.
Place the code below in your main window.
protected override void OnSourceInitialized(EventArgs e)
{
// For added compatibility, turn off hardware rendering
HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
HwndTarget hwndTarget = hwndSource.CompositionTarget;
hwndTarget.RenderMode = RenderMode.SoftwareOnly;
base.OnSourceInitialized(e);
}
You may also need.
using System.Windows.Interop;
Backstory in Silverlight 5 dynamic stream URI setting.
My goal (as an artifact from the link) is to resolve why I'm rendering audio fine but not video for smooth streaming files in dynamically rendered (InitParam) smooth URIs.
Basically, I need to pass a dynamically generated smooth stream URI into the player and set "Media Source" correctly. Which I believe I've done.
Testing statically linked MediaSource="http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/Manifest"/ works fine for both video and audio.
However dynamically generating the PlayListItem doesn't.
The code..
MainPage.xaml
<UserControl x:Class="SilverlightApplicationDPCS.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"
xmlns:Core="clr-namespace:Microsoft.SilverlightMediaFramework.Core;assembly=Microsoft.SilverlightMediaFramework.Core"
xmlns:Media="clr-namespace:Microsoft.SilverlightMediaFramework.Core.Media;assembly=Microsoft.SilverlightMediaFramework.Core"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White" xmlns:smf="http://schemas.microsoft.com/smf/2010/xaml/player">
<smf:SMFPlayer HorizontalAlignment="Stretch" Margin="0"
x:Name="sMFPlayer" VerticalAlignment="Stretch" />
<Core:SMFPlayer AutoPlay="True" AutoLoad="True">
<Core:SMFPlayer.Playlist>
</Core:SMFPlayer.Playlist>
</Core:SMFPlayer>
</Grid>
MainPage.xaml.cs (overriding the consumption of the InitParam param for debug purposes statically setting uriString)
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
App currentApp = (App)Application.Current;
string uriString = "http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/Manifest";
if (sMFPlayer.Playlist.Count > 0)
sMFPlayer.Playlist.Clear();
sMFPlayer.Playlist.Add(new PlaylistItem
{
MediaSource = new Uri(uriString, UriKind.Absolute),
DeliveryMethod = DeliveryMethods.AdaptiveStreaming
});
sMFPlayer.Play();
All references below are version 2.012.0605.0, other than Microsoft.Web.Media.SmoothStreaming.dll version 2.0.157.18
Project References:
Microsoft.SilverlightMediaFramework.Core.dll
Microsoft.SilverlightMediaFramework.Plugins.dll
Microsoft.SilverlightMediaFramework.Plugins.SmoothStreaming.dll
Microsoft.SilverlightMediaFramework.Utilities.dll
Microsoft.Web.Media.SmoothStreaming.dll
Compiler Environment:
Microsoft Media Platform: Player Framework
Silverlight 5
Windows 7
Visual Studio 2015
Browser: Run-time Internet Explorer 11.
Fiddler shows video and audio smooth fragments..
GET http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/QualityLevels(688000)/Fragments(video=60050000) HTTP/1.1
GET http://playready.directtaps.net/smoothstreaming/TTLSS720VC1/To_The_Limit_720.ism/QualityLevels(128000)/Fragments(audio=61765079) HTTP/1.1
From the above StackOverlow link, where I'm left is:
Why I can't see video from multiple smooth streaming sources in Silverlight 5, nor player controls being operative, but hear audio and see video and audio packets in Fiddler is perplexing.
Grateful for any ideas to fix this.
Hi i just recently found out that you can use components from WPF and add into windows form just by creating them and later adding then into the form as element Host
So what i am trying to do is to create a video player using MediaElement and i also know that you can use Direct X or use Windows Media player for this put i want to custom make some controls in this so here is my question
when i try to add a the media element into my windows form it give me this error
here's my code for the mediaelement wpf
<UserControl x:Class="Videoplayer_2._0.MediaPlayer"
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"
xmlns:local="clr-namespace:Videoplayer_2._0"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<MediaElement x:Name="mediaElement" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
</UserControl>
So is adding mediaElement just doesn't work or i did something wrong and also i added a WPF slider into the form also just saying because i have no idea if it will affect it or not
You just need to restart Visual Studio I think.