Hello friends,
Today I am going to write one more important article regarding the Video and Audio files in web application. By this application you can view the .avi, .mpeg files in your web browser.
For this application you should have the avi or mpeg files to load in the web browser. This application contains a list box and object tag with a play button. Depends on your selection from the list box you can find the videos will load in the media player in your browser. Just copy and paste the following code in your .aspx page’s form tag.
=================================================================================================
<div>
<asp:ListBox ID=”lstFiles” runat=”server” SelectionMode=”Multiple”>
<!–HERE YOU HAVE TO GIVE THESE FILES WHICH ARE EXIST IN YOUR PROJECT–>
<asp:ListItem>BLUR16.AVI</asp:ListItem>
<asp:ListItem>BLUR24.AVI</asp:ListItem>
<asp:ListItem>CINEAPK.AVI</asp:ListItem>
</asp:ListBox>
<br />
<asp:Button ID=”Button1″ runat=”server” Text=”Play” OnClick=”Button1_Click” /><br />
<br />
<!–HERE WE ARE USING LITERAL TAG TO WRITE THE HTML DYNAMICALLY–>
<asp:Literal ID=”Literal1″ Visible=”true” runat=”server”></asp:Literal>
</div>
=================================================================================================
Write the following code in your code behind file(i.e. .aspx.CS) This code will be in your button’s click event.
=================================================================================================
//HERE WE ARE WRITING IN A FILE (test.wvx). THIS FILE IS THE PLAYLIST FILE FOR THE MEDIA PLAYER, LATER WE WILL ASSIGN THIS FILE TO
//THE OBJECT TAG
StreamWriter sw = new StreamWriter(“test.wvx”);
//Write lines to File
sw.WriteLine(“<ASX VERSION=\”3.0\”>”);for (int i = 0; i < lstFiles.Items.Count; i++)
{
if (lstFiles.Items[i].Selected)
{
sw.WriteLine(“<ENTRY>”);
sw.WriteLine(“<REF HREF=\”" + lstFiles.Items[i].Value + “\” />”);
sw.WriteLine(“<Title>Testing 00</Title>”);
sw.WriteLine(“<Author>CIPL 00</Author>”);
sw.WriteLine(“<Copyright>VBM 01</Copyright>”);
sw.WriteLine(“<Banner></Banner>”);
sw.WriteLine(“</ENTRY>”);
}
}sw.WriteLine(“</ASX>”);
//Close the file
sw.Close();StringBuilder sb=new StringBuilder();
sb.Append(“<object data=’test.wvx’ classid=’55274-641-1620264-23142′ runat=’server’ id=’audio’ name=’audio’ type=’video/x-ms-wvx’ style=’width:400px; height:309px’>”);
sb.Append(“<param name=’src’ id=’wvxfile’ value=’test.wvx’ valuetype=’ref’ />”);
sb.Append(“<param name=’showcontrols’ value=’1′ valuetype=’data’ />”);
sb.Append(“<param name=’SendPlayStateChangeEvents’ value=’true’>”);
sb.Append(“<param name=’showstatusbar’ value=’1′ valuetype=’data’ />”);
sb.Append(“<param name=’autostart’ value=’1′ valuetype=’data’ />”);
sb.Append(“<param name=’volume’ value=’0′ valuetype=’data’ />”);
sb.Append(“<param name=’PlayCount’ value=’1′ valuetype=’data’ />”);
sb.Append(“</object>”);Literal1.Text = sb.ToString();
=================================================================================================
Just go through this code. If you are unable to create file, please give full writes to your project folder. That will allow you to create file named test.wvx. Now run the project. Select the multiple files from the list box and u can see that the files are loading in the web browser in sequenct.
You can add your suggestions and comments regarding this article.
So Enjoy programming….
Regards,
Vijay Modi.
Hi, this is code is working fine at local host but when i run this at server its not working.
Plz Help ASAP.
Thankx
By: Javed Ahmad on March 1, 2008
at 9:38 am
Hi Javed,
I think you have to check the configuration of the server. There may something wrong on the server.
Regards,
Vijay Modi
By: Vijay Modi on March 1, 2008
at 10:30 am
Hi Modi,
I ahve given full control all pages,folder and test.wvx file but still i am unable to play mp3 at server side.
FYI i am not using a list control i am passing the file name @ streamWriter Line(REF HREF=”);
thankx 4 replay
By: Javed on March 3, 2008
at 11:20 am
Hi Javed,
Please change the object tag with the following one:
type=”application/x-shockwave-flash”
If it will not resolve. Please check your window media player and its classid. I think it will resolve your problem.
Thank you for your comment. I hope it will help you.
Regards,
Vijay Modi
By: Vijay Modi on March 3, 2008
at 11:57 am
Hi Modi,
Thankx a lot, i have resolve that problem.there was just path incorrect of mp3 file.
Thankx Vijay Modi
Regards
Javed Ahmad
By: Javed on March 6, 2008
at 10:46 am
i try your example but it is not proper coded it give some error of delegate and interface.
By: rajesh on March 20, 2008
at 11:08 am
Thank you, I’ll try..
By: Telugu Movie Reviews on May 16, 2008
at 7:50 am
hi Modi,
thanks alot,u done a great help 2 me..!!!
By: kumar on June 11, 2008
at 8:14 pm
hi modi,
thanks alot,i got a solution…!!!
By: shekar on June 12, 2008
at 12:40 pm
hi vijay,
please tell me how to play videos in webpage………
here im using datalist………..
play videos in that like orkut videos………..
please help me………..
By: Sunil Kumar Deeti on June 24, 2008
at 2:00 pm
Hi Vijay Modi.
Thank you very much.it’s work well.
By: Balamurugan Shlok on August 1, 2008
at 10:16 am
We have included ur codings as it is but it’s not displaying anything. Just media player is displaying a blank screen. What to do now. This codings is very urgent to us. Please help us
Thank u
By: Mangai on September 9, 2008
at 9:10 am
Thanks Modi. It was great article.
Is the any way to move next or previous song??
By: Venkat on March 27, 2009
at 3:27 am
Vijay
Is the test.wxv file created on the fly or do I have to create it myself?
By: Robert on September 2, 2009
at 6:17 pm
Vijay
I am running your application on a windows 2003 server and am getting this message ” Access to the path ‘c:\windows\system32\inetsrv\test.wvx’ is denied.
Any idea?
Thanks
By: Rob on September 3, 2009
at 11:22 am
Rob, please check there might be the permission issue of “inetsrv” folder.
Regards,
Vijay Modi
By: Vijay Modi on September 25, 2009
at 9:31 am