Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai i am using MediaElement control in WPF to play video files, when I build the application and if i run through any other pc it is working video can be visible and audio as well as but in my pc! video is not visible only audio can able to hear i am using win 10'OS and tested in other win10'OS PC's there no issues. anyone helps me to find out the issue?
Quote:
in windows media player and in all other player i can able to play the video


What I have tried:

in XAML page

Window x:Class="Media.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Media" Height="400" Width="460"
    >
    <Grid>
    <TextBox Height="20" Margin="10,7,134,0" Name="MediaPathTextBox" VerticalAlignment="Top"  ></TextBox>
    <Button Height="20" HorizontalAlignment="Right" Margin="0,6,14,0" Name="BrowseButton" 
            VerticalAlignment="Top" Width="94" Click="BrowseClick">
        Browse Media
    </Button>
    <MediaElement Canvas.Left="20" Canvas.Top ="40" 
            Name="VideoControl" LoadedBehavior="Manual" UnloadedBehavior="Stop" >
      </MediaElement>
    
    <Button Height="23" HorizontalAlignment="Left" Margin="15,0,0,13" 
            Name="PlayButton" VerticalAlignment="Bottom" Width="75" 
            Click="PlayClick">
      Play</Button>
    <Button Height="23" HorizontalAlignment="Left" Margin="103,0,0,13" 
            Name="PauseButton" VerticalAlignment="Bottom" Width="75" 
            Click="PauseClick">
      Pause</Button>
    <Button Height="23" Margin="191,0,186,13" Name="StopButton" 
            VerticalAlignment="Bottom"  Click="StopClick">
      Stop</Button>
  </Grid>
</Window>



in .cs page

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;


namespace Media
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();
            VideoControl.Volume = 100;
            VideoControl.Width = 440;
            VideoControl.Height = 280;
         }

        void BrowseClick(Object sender, EventArgs e)
        {
            OpenFileDialog openDlg = new OpenFileDialog();
            openDlg.InitialDirectory = @"c:\";
            openDlg.ShowDialog();
            MediaPathTextBox.Text = openDlg.FileName;
        }

        void PlayClick(object sender, EventArgs e)
        {
            if (MediaPathTextBox.Text.Length <= 0)
            {
                System.Windows.Forms.MessageBox.Show("Enter a valid media file");
                return;
            }
            VideoControl.Source = new Uri(MediaPathTextBox.Text);
            VideoControl.Play();
        }
        void PauseClick(object sender, EventArgs e)
        {
            VideoControl.Pause();
        }
        void StopClick(object sender, EventArgs e)
        {
            VideoControl.Stop();
        }
      
        

    }
}
Posted
Updated 4-Aug-21 21:44pm
v3

1 solution

It seems not to be a problem with your programme.
If the video plays correctly on some computers
and does not play correctly on other computers
then it is a problem of missing codecs.
Can you play your video with other video players?
You must find out what codec you need in order to play your video.

Maybe you could also try Codec Guide: K-Lite Codec Pack - For Windows 10 / 8.1 / 7 / Vista[^] in order to install the missing codecs.
 
Share this answer
 
Comments
Fazil13 5-Aug-21 3:40am    
yes,in windows media player and in all other player i can able to play the video.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900