Click here to Skip to main content
16,016,760 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
In the C# program, I want to display and play a video from within my program in a window.

The path that I give to my video source as an internal path of the embed type works in design mode, but it does not display the video when running the program, but if I give it the direct address of the file in Windows, it works.

This is despite the fact that if I want to show a photo or gif from the same path, it works and shows well


What I need :

In C# WPF on Visual studio 2019 in Windows 10, I want to show and play a video inside a My window from the app not directly path

What have I done :

I have included that video in my project, then I set the path for the video and it shows it to me in design view! :



What have I tried and my code :

so I decided to try it in three-way, also to try to show a gif for sure about the path.

Embedded path
Normal Path
Direct path on windows
but only the direct path works! While the same embedded path works for GIF

MyGIF : Source="pack://application:,,,/Medias/1Correctmation.gif" => works fine

My Video : Source="pack://application:,,,/Medias/Video1.mp4" => not working

My Video : Source="C:\Users\user\Desktop\Video1.mp4" => workis fine but I don't want this directly path

also for my video file I tried these BuildAction:

Embedded
Resource
Content Resource
none of them work.



code from stackoverflow:

https://stackoverflow.com/questions/74423614/how-to-show-an-embedded-video-inside-of-a-window-in-c-sharp-wpf-application[^]

What I have tried:

What have I tried and my code :

so I decided to try it in three-way, also to try to show a gif for sure about the path.

Embedded path
Normal Path
Direct path on windows
but only the direct path works! While the same embedded path works for GIF

MyGIF : Source="pack://application:,,,/Medias/1Correctmation.gif" => works fine

My Video : Source="pack://application:,,,/Medias/Video1.mp4" => not working

My Video : Source="C:\Users\user\Desktop\Video1.mp4" => workis fine but I don't want this directly path

also for my video file I tried these BuildAction:

Embedded
Resource
Content Resource
none of them work.


XML
<pre> <Grid>
        <Label Content="Embeded Video :" HorizontalAlignment="Left" Margin="10,34,0,0" VerticalAlignment="Top" Width="100"/>
        <MediaElement x:Name="Embd_Video1_mp4" Margin="115,10,499,309" Stretch="Fill" Source="pack://application:,,,/Medias/Video1.mp4"/>
        
        <Label Content="Normal Path :" HorizontalAlignment="Left" Margin="10,172,0,0" VerticalAlignment="Top" Width="82"/>
        <MediaElement x:Name="Normal_Video1_mp4" Margin="115,134,444,154" Stretch="Fill" Source="Medias/Video1.mp4"/>
        
        <Label Content="Direct Path :" HorizontalAlignment="Left" Margin="10,345,0,0" VerticalAlignment="Top" Width="82"/>
        <MediaElement x:Name="Dir_Video1_mp4" Margin="115,278,331,10" Stretch="Fill" Source="C:\Users\user\Desktop\Video1.mp4"/>
        
        <Label Content="Embeded Gif Here ↓:" HorizontalAlignment="Left" Margin="452,34,0,0" VerticalAlignment="Top" Width="114"/>
        <Image Margin="452,65,30,189" Source="pack://application:,,,/Medias/1Correctmation.gif" />
    </Grid>


Source Code : https://mega.nz/file/B1Zi2S6C#VtCk8xcdabekNIySc9-6C2yMNdV5z-qHoTCUnYl0CXA
Posted
Updated 13-Nov-22 19:05pm
v5
Comments
Graeme_Grant 14-Nov-22 0:33am    
What code and what problem?
mojtabahakimian 14-Nov-22 0:36am    
sorry , I have updated
Graeme_Grant 14-Nov-22 0:38am    
So you post a detailed question on Stackoverflow, force us to go there, and expect us to answer it here?
mojtabahakimian 14-Nov-22 1:02am    
Ok sir, I will create cross post here
Graeme_Grant 14-Nov-22 1:08am    
Error message or binding error?

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