hosting mp3 files in an aspx page

A

Andy B

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?
 
C

Coskun SUNALI [MVP]

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.

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

Andy B

Do you have any tutorials or resources on how to do the below? using asah?
files with mp3 files in an iframe?
Coskun SUNALI said:
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.

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

Andy B said:
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?
 
C

Coskun SUNALI [MVP]

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>

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

Andy B said:
Do you have any tutorials or resources on how to do the below? using asah?
files with mp3 files in an iframe?
Coskun SUNALI said:
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.

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

Andy B said:
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?
 
A

Andy B

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.


Coskun SUNALI said:
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>

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

Andy B said:
Do you have any tutorials or resources on how to do the below? using
asah? files with mp3 files in an iframe?
Coskun SUNALI said:
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.

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

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?
 
P

Peter Bromberg [C# MVP]

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
 
C

Coskun SUNALI [MVP]

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.

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

Andy B said:
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.


Coskun SUNALI said:
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>

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

Andy B said:
Do you have any tutorials or resources on how to do the below? using
asah? files with mp3 files in an iframe?
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.

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

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?
 
A

Andy B

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?


Peter Bromberg said:
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


Andy B said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top