ASP.Net + Audio / Video files in sequence

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.

Advertisements

About Vijay Modi

Having 12+ years of experience in web application development. Expertise in various domains like E-Commerce, E-Learning, Insurance. I have expertise in web application development, window application development, Performance improvement, bug fixing etc. I am believing in quality work and achieving deadlines. Also like to work on new technologies and quick learner.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

18 Responses to ASP.Net + Audio / Video files in sequence

  1. Javed Ahmad says:

    Hi, this is code is working fine at local host but when i run this at server its not working.

    Plz Help ASAP.

    Thankx

  2. Vijay Modi says:

    Hi Javed,

    I think you have to check the configuration of the server. There may something wrong on the server.

    Regards,
    Vijay Modi

  3. Javed says:

    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

  4. Vijay Modi says:

    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

  5. Javed says:

    Hi Modi,

    Thankx a lot, i have resolve that problem.there was just path incorrect of mp3 file.

    Thankx Vijay Modi

    Regards
    Javed Ahmad

  6. rajesh says:

    i try your example but it is not proper coded it give some error of delegate and interface.

  7. Thank you, I’ll try..

  8. kumar says:

    hi Modi,
    thanks alot,u done a great help 2 me..!!!

  9. shekar says:

    hi modi,
    thanks alot,i got a solution…!!!

  10. Sunil Kumar Deeti says:

    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………..

  11. Balamurugan Shlok says:

    Hi Vijay Modi.
    Thank you very much.it’s work well.

  12. Mangai says:

    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

  13. Venkat says:

    Thanks Modi. It was great article.

    Is the any way to move next or previous song??

  14. Robert says:

    Vijay

    Is the test.wxv file created on the fly or do I have to create it myself?

  15. Rob says:

    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

  16. This is very informative post. I love this and I will check your blog again.

  17. Dilip Kumar Tripathy says:

    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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s