Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

hosting mp3 files in an aspx page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy B - 05 Feb 2008 17:02 GMT
Hi...

I have an aspx page with a gridView on it. There is a HyperLink field on the
gridView that goes to the following link: PlayAudio.aspx?ID={0} ({0} is the
id number of the audio in the database). PlayAudio.aspx gets the audio
itself from the database and streams it to the user. The code below is in
the PlayAudio.aspx file:

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;

public partial class PlayAudio : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

int ID = Convert.ToInt32(Request.QueryString["ID"]);

// Get information about the specified song

AudioDB AudioHelper = new AudioDB();

AudioDataSet.AudioDataTable Songs = AudioHelper.GetSongByID(ID);

AudioDataSet.AudioRow Song = Songs[0];

//output the song now

Response.ContentType = "text/html";

Response.BinaryWrite(Song.Audio);

}

}

What I need to do, is make it possible to embed this aspx page inside of a
main page where the audio is played without bringing up mediaplayer and
leaves me the ability to show song details on the page at the same time the
file plays. How would I do this?
Coskun SUNALI [MVP] - 05 Feb 2008 17:20 GMT
Hi Andy,

First of all, I would suggest you to use ASHX files instead of ASPX files.
This will avoid the web server running an ASPX page and paying resources to
complete its life cycle.

For your problem, I may suggest you considering to use an IFrame and calling
the ASHX file from that IFrame.

Hope it helps.

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Hi...
>
[quoted text clipped - 56 lines]
> leaves me the ability to show song details on the page at the same time
> the file plays. How would I do this?
Andy B - 05 Feb 2008 18:03 GMT
Do you have any tutorials or resources on how to do the below? using asah?
files with mp3 files in an iframe?
> Hi Andy,
>
[quoted text clipped - 67 lines]
>> leaves me the ability to show song details on the page at the same time
>> the file plays. How would I do this?
Coskun SUNALI [MVP] - 05 Feb 2008 19:39 GMT
Hi Andy,

You can read about creating a HttpHandler (ASHX) class at
http://www.developerfusion.co.uk/show/2516/

Also, using the IFrame is easy;

<iframe src="video.ashx?videoid=123" style="width: 0px; height:
0px;"></iframe>

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Do you have any tutorials or resources on how to do the below? using asah?
> files with mp3 files in an iframe?
[quoted text clipped - 69 lines]
>>> and leaves me the ability to show song details on the page at the same
>>> time the file plays. How would I do this?
Andy B - 05 Feb 2008 21:09 GMT
Hi...

I got the ashx thing to work. It wasn't that hard. All I had to do was move
the code from PlayAudio.aspx page_load event and put it in ProcessRequest
event of the mp3.ashx file and prepend Context. before all of the response
and request calls. Now that I have that working fine, I have to embed the
audio inside the page itself. I.e. prevent media player from popping up and
playing the file but still be able to play it. I was looking around and saw
that you can use the <object> html tag to embed audio in a page. So, I have
this in my PlayAudio.aspx page:
<object id="AudioFrame" type="audio/mpeg" runat="server" />

So far, so good. Now in the CodeBehind for the PlayAudio.aspx page I have
this:

protected void Page_Load(object sender, EventArgs e) {
//set the data for the audio
AudioFrame.Attributes["data"]="mp3.ashx?ID="+Request.QueryString["ID"];
}

Ok... compiles fine. I run ShowAudio.aspx (it has a list of all audio in the
database with a play link next to it). I pick a track to play and click the
play link. The confusing part comes next... I get this error:

Parser Error Message: An object tag must contain a Class, ClassID or ProgID
attribute.

I read somewhere online that the reason for this problem is something to do
with the runat="server" being in the <object> tag. I would rather keep this
serverside if possible. I just have no clue what class, classid or progid
are used for. When I looked at class and classid for the html tag in a
reference guide, it told me that the class/classid is what identifies the
actual source of the object in the windows registry. It is starting to get
confusing now. Is there any way to fix this? If there is a way that I can
make the <object> client side and still refer to it in codeBehind, then that
would work for me as long as I can still use something like
data="mp3.ashx?ID="+Request.QueryString["ID"] format.

> Hi Andy,
>
[quoted text clipped - 79 lines]
>>>> mediaplayer and leaves me the ability to show song details on the page
>>>> at the same time the file plays. How would I do this?
Coskun SUNALI [MVP] - 05 Feb 2008 21:21 GMT
Hi Andy,

Looks like I got your question wrong so I suggested using an IFrame instead
of an embed or object tag. Though using the ASHX file instead of an ASPX
file to response a file is still fine.

Peter already responded to your object question. I would double his
solution.

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Hi...
>
[quoted text clipped - 117 lines]
>>>>> mediaplayer and leaves me the ability to show song details on the page
>>>>> at the same time the file plays. How would I do this?
Peter Bromberg [C# MVP] - 05 Feb 2008 21:15 GMT
Use the standard "embed" tag with runat="server' attribute and set the src
property programmatically in your codebehind. example:

//IN THE aspx:

<form id="form1" runat="server">
   <div>    
    <embed runat="server" id="wma" type="application/x-mplayer2"
        pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
          Name="MediaPlayer" src=""
           AutoStart=1 ShowStatusBar=0 volume=-1
            HEIGHT=16 WIDTH=16>
    </embed>  
   </div>
   </form>

      // IN THE PAGE codebehind
       protected void Page_Load(object sender, EventArgs e)
       {
        // you can set this programmatically to your page, etc.
           this.wma.Attributes["src"] =
"http://www.eggheadcafe.com/articles/HMSPinafore.wma";

       }

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hi...
>
[quoted text clipped - 56 lines]
> leaves me the ability to show song details on the page at the same time the
> file plays. How would I do this?
Peter Bromberg [C# MVP] - 05 Feb 2008 21:29 GMT
P.S. -- You can also use Response.BinaryWrite on what you get out of the
database and the Embed control on the calling page will be happy.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hi...
>
[quoted text clipped - 56 lines]
> leaves me the ability to show song details on the page at the same time the
> file plays. How would I do this?
Andy B - 06 Feb 2008 01:50 GMT
Sorry... the embed control you gave in the other message didnt work. No
errors, but absolutely no sound at all. I don't even think the embed control
was able to get the sound out of the db table... any other ideas?

> P.S. -- You can also use Response.BinaryWrite on what you get out of the
> database and the Embed control on the calling page will be happy.
[quoted text clipped - 67 lines]
>> the
>> file plays. How would I do this?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.