Posts

Showing posts with the label MediaElement

Using embedded MediaElement controls to play videos in WPF / MVVM

Image
Essentially the same as these instructions , but using a purely MVVM approach and without the additional stop / start / pause etc buttons - the application just 'sees' the MP4 media file it needs to play and plays it upon startup. Step 1: Create a new WPF Application Step 2: Create the Main Window ViewModel classes Add the following classes to your project: MainWindowViewModel.cs [code language="csharp"] namespace MediaElement { public class MainWindowViewModel : BaseViewModel { private string _url; public MainWindowViewModel() { Url = "E:\\temp\\SampleMp4File.mp4"; } public string Url { get { return _url; } set { if (_url == value) return; _url = value; OnPropertyChanged("Url"); } } } } [/code] BaseViewModel.cs [code language="csharp"] usin...