Click here to Skip to main content
15,748,248 members
Articles / Web Development / ASP.NET
Posted 27 May 2011

Tagged as


17 bookmarked

Play Video files in Web sites

Rate me:
Please Sign up or sign in to vote.
4.48/5 (17 votes)
19 Jul 2011CPOL
Play Video files in Web sites
There are lots of situations where we have to play a video in our web page.

I describe the way of playing video in your webpage. There are two processes I illustrate here. One is from Html or Source view, and another is from code behind.

Process One:

<object id="MediaPlayer" height="200" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
standby="Loading Windows Media Player components..." type="application/x-oleobject" width="200">
<param name="FileName" value="mobile.wmv">
<param name="ShowControls" value="true">
<param name="ShowStatusBar" value="false">
<param name="ShowDisplay" value="false">
<param name="autostart" value="true">
<embed type="application/x-mplayer2" src="mobile.wmv" name="MediaPlayer" width="100%"
height="190" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed> 
<br /></object>


BY Using Interop, you can acheive this by the following three methods:
Process Two

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Media;
using WMPLib; //Add this COM Component Reference to your project

public partial class Play : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void btnPlay_Click(object sender, EventArgs e)
string _path = "Your File Path";
//Method 1 using sound player class

SoundPlayer _sm = new SoundPlayer(_path);

//Method 2

Microsoft.VisualBasic.Devices.Audio _mvda = new Microsoft.VisualBasic.Devices.Audio();
_mvda.Play(_path, Microsoft.VisualBasic.AudioPlayMode.Background);

//Method 3 using WindowsMediaPlayer Class

WindowsMediaPlayerClass _wmpc = new WindowsMediaPlayerClass();


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

Written By
Software Developer India
India India
Total DotNet/Programming Solution

I am Prasanta Banerjee. I am an Asp.Net Developer. My site:
If any body wants to prepare for interview is the good site.

Comments and Discussions

QuestionError - HRESULT: 0xC00D1329 Pin
atulxxx26-Jun-12 4:52
atulxxx26-Jun-12 4:52 
GeneralMy vote of 5 Pin
Prasanta_Prince15-May-12 19:42
Prasanta_Prince15-May-12 19:42 
GeneralReason for my vote of 3 it 's good Pin
Nima Heydarzadeh8-Feb-12 23:35
Nima Heydarzadeh8-Feb-12 23:35 
GeneralYeh.. the second plays in server! don't worry the admin will... Pin
After20506-Jun-11 2:32
After20506-Jun-11 2:32 
GeneralI have given two different approaches. Pin
Prasanta_Prince31-May-11 6:15
Prasanta_Prince31-May-11 6:15 
GeneralRe: One of which plays the sound or video on the *server*, where... Pin
Richard Deeming31-May-11 6:48
mveRichard Deeming31-May-11 6:48 
One of which plays the sound or video on the *server*, where nobody is likely to notice it.

It works when you're debugging the code locally, because then the client and the server are both the same. If you deploy this to a real server, the client will never hear the sound or see the video.
GeneralProcess one plays the video or sound on the *client*; proces... Pin
Richard Deeming31-May-11 3:52
mveRichard Deeming31-May-11 3:52 
GeneralExcellent tip, thanks for sharing! 5* Pin
DrABELL27-May-11 15:06
DrABELL27-May-11 15:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.