Reputation: 19
I am trying to create a Windows Form application to play .WMV files.
I have 5 videos that i have added to my project, within a Videos folder.
I have created a button for each video, 5.
When a button is clicked, Button1, i want to be able to open Video1.. Using Windows Media Player for example.
Code so far::
private void PlayVideo1_Click(object sender, EventArgs e)
{
// Open Windows Media Player
System.Diagnostics.Process.Start("wmplayer.exe");
// Play Video1.
Process.Start("Video1.wmv");
}
Please can you advise what i am doing wrong?
========================
Update:
Can a similar code be used for WPF?
Upvotes: 1
Views: 3435
Reputation: 10357
Try to use Audio Video Playback from Microsoft.DirectX.AudioVideoPlayback
namespace.
or use Windows Media Player Control
on your form. see this MSDN article:
a sample code:
private void PlayFile(String url)
{
Player = new WMPLib.WindowsMediaPlayer();
Player.URL = url;
Player.controls.play();
}
Upvotes: 0
Reputation: 143
Is the WMV files set to "Copy always" in the "Copy to output Directory" property? Like in the picture below:
If it is, then the files are going to the same directory as the application, the next step is to run the WMV from the propert path,
Your code:
Process.Start("Video1.wmv");
Is not wrong to want to start the WMV directly (that way, the default player in the target machine will run), but you need to send the full path (C:\Video.WMV for eg)
If the WMV files are inside a VIDEOS folder within your application, you could change to do like this for eg:
Process.Start(Path.Combine(Application.StartupPath, "VIDEOS/Video1.wmv"));
Upvotes: 1