Hi all,
Can anyone tell me how can we play the video(.wmv) in C# window application .................?
Let i have some links on window form, As the user click on that link, related video should start playing.....
And i am using VS2008.......
Kindly help me regarding this............

Recommended Answers

All 17 Replies

You can embed windows media player in your application which can play videos from your harddrive or stream them from a URL.

Add a reference to "Windows Media Player" aka Interop.WMPLib.dll, and then navigate to the controls in that DLL (using the "customize toolbox" menu option). You will see a media player control. Drop it on your form and away you go.

commented: Good suggestion. +6

. Here is a good example to play a video using DirectX - .

You can also play video in a 3d space using the XNA framework if you want to do some fanciness

commented: Great! +6

Thank you all for your replies..............

@sknake
Well sknake i want to to inbuilt video in my application, and want to play videos from there, like as user click on link, related video should start on form.
Can i do this thing as well with add to reference of Window Media Player in my application.................?

You can also play video in a 3d space using the XNA framework if you want to do some fanciness

jbennet can you please tell me how can i use XNA framework in my application, i never used this..........
Can you explain me something more about this..........?

Good suggestion from scott. Here is a good example to play a video using DirectX - http://www.codeproject.com/KB/graphics/zMoviePlayer.aspx. You may use MCI - Media Control Interface API to play video.

One thing i want to ask you, if i am using DirectX to develop my application, So is it necessary that DirectX should also be installed on User end..........?

You can embed windows media player in your application which can play videos from your harddrive or stream them from a URL.

Add a reference to "Windows Media Player" aka Interop.WMPLib.dll, and then navigate to the controls in that DLL (using the "customize toolbox" menu option). You will see a media player control. Drop it on your form and away you go.

Well sknake i have done whatever you mentioned here,
BUt now tell me how can i run the video inside this........?

Vibhorg -- Adatapost provided the article you should read regarding embedding the media player. Take a look and see if that solution meets your needs.

Well sknake i have done whatever you mentioned here,
BUt now tell me how can i run the video inside this........?

Take a look at this article - http://msdn.microsoft.com/en-us/library/dd562851(VS.85).aspx

Vibhorg -- Adatapost provided the article you should read regarding embedding the media player. Take a look and see if that solution meets your needs.

Yes, but i just have one query regarding this, that the code behind the play button is:

axWindowsMediaPlayer1.URL = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\Videofile.wmv";

In this it is load the video from our system(hard drive of user), but in my application i have inbuilt some videos with it, and i want that when user click on play button so video load from that location(In to my application).
Kindly help me in that Sknake..

This depends how you have the videos inbuilt. If they're compiled in as an embedded resource you could do something like:

private void button3_Click(object sender, EventArgs e)
    {
      string tmpFile = System.IO.Path.GetTempFileName();
      File.WriteAllBytes(tmpFile, Properties.Resources.File_MOV);
      //mediaPlayer.URL = tmpFile;
      //mediaPlayer.Play();
    }

Be sure to clean up your temp files when the application closes.

This depends how you have the videos inbuilt. If they're compiled in as an embedded resource you could do something like:

private void button3_Click(object sender, EventArgs e)
    {
      string tmpFile = System.IO.Path.GetTempFileName();
      File.WriteAllBytes(tmpFile, Properties.Resources.File_MOV);
      //mediaPlayer.URL = tmpFile;
      //mediaPlayer.Play();
    }

Be sure to clean up your temp files when the application closes.

No Sknake this is not what i want,
Let i have a folder(name video) in my application, and i m put(copy) some videos in that folder, now i want to play these videos into my form.
How can i do this ..............
I thing now my problem is clear to you.....

Just set the path to C:\Program Files\Wherever you installer your application\Videos\video1.mpg and play the video. I don't understand why this is a problem?

Just set the path to C:\Program Files\Wherever you installer your application\Videos\video1.mpg and play the video. I don't understand why this is a problem?

Okey thank you..........

Its a far back reference, but using DirectX is a very good practice. and all windows computers XP and up have DirectX installed. It's installed with windows and comes as an automatic update as well. The managed directX libraries have very easy to use audio and video objects that is as simple as passing it a filepath, giing it a parent control to play on, and calling play.

This is just for future reference. Glad you already have this solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.