0

on my window_loaded, i put this:

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            mediaElement1.Source = new Uri("/WpfTest;component/Videos/acar_ikan_masin.mp4", UriKind.Relative);
        }

and the file acar_ikan_masin.mp4 is already in my project (I add it using Add>Existing Item> to a new folder Videos which I created). but it seems vs can't find the video. the mediaelement is working fine because i could just drag and drop any video file to the mediaelement and it will play. what is the correct way to set the source, for a file which has already been added to the project?

imin
  • 4,504
  • 13
  • 56
  • 103

2 Answers2

3

it seems i just need to change the path to

mediaElement1.Source = new Uri(@"Videos/acar_ikan_masin.mp4", UriKind.Relative);

and set the file's copy to output directory to 'copy always'

imin
  • 4,504
  • 13
  • 56
  • 103
0

MediaElement uses window media player in background so to use this.

make sure you have the latest WMP in you system. and that WMP also support the mp4 type codecs. if not than install the wmp codec pack.

try with wmv it will work.

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Media Files (*.wmv)|*.wmv";
            ofd.ShowDialog();
            mediaplayer1.source = new  Uri(ofd.FileName); 
JSJ
  • 5,653
  • 3
  • 25
  • 32