473,289 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Datagrid Hyperlink field to play file system wave file help.

Im working with VS 2005 and trying to use a Hyperlink field in a datagrid to
play a wave file that is not located in the website folders but is in a plain
folder on the same machine, windows 2003 server, WMP 10.0 .

If I type the full path in an IE address field it plays the file in WMP

When I test my Web page ( running the debugger in VS.)
The datagrid has a column called "MsgFile" with the full path to the wave
file e.g. c:\pf\app\audio\3\19.wav. Another Hyperlink column in the grid
has DataNavigateURLFields pointing to the MsgFile field and that works.

But for the hyperlink's DataNavigateURLFormatString I've tried:

1. {0} - which results in the ':' from the path being removed and converts
backslash to forward slash (c/pf/app/audio/3/19.wav) and hence file not found
error.

2. http://{0} - also removes the ':' from the path and hence file not found
error.

3. http://localhost/{0} - leaves the ':' in the path to result in what I
believe is the correct URL http://localhost/c:/pf/app/audio/3/19.wav but
results in Page Not Found.

Hopefully it is possible to play a wave file that is not in the website
folder.

The simple question is what format string needed in the
DataNavigateURLFormatString to get the file to play?
Any assistance is appreciated.
--
Thanks
Morris
Aug 24 '06 #1
9 5566
Hi Morris,

From your description, I understand your web application will display some
links on one page (through grid) and the link will point to some wav sound
so that the user can play it when click on the link. The problem is that
the wav files is in a non-virtual directory(accessible through http
address) on the server, correct?

As for this problem, I think it is doable and have several means. I'd like
to confirm following things first:

1. Are you developing through ASP.NET 1.1/VS 2003 or ASP.NET 2.0/VS 2005?

2. As for the media file(wav), how do you want to play it to client user,
among the following options:

** let the client user directly link to the media and the browser will
choose a player on the client to play it.

** embed some activex or sound tag in web page and use let the browser to
play it, thus , the client will not launch a separate player when user
click the link.
As for the wav file linking problem, I don't think we can directly use the
physical path(like c:\media\.....) because this path is not recommend for
internet application. also, the "c:\media\" physical path is only valid to
the server machine, since the page is finally displayed in client browser,
the browser will try locating the file on the client machine's disk and
won't be able to get the file.
To resolve this, I suggest you consider the following means:

1)Create an ASP.NET web page or HttpHandler which will programmtically read
the file from the non-web folder and then write it out as response stream.
e.g.

suppose the page's name is "MediaOutput.aspx", we add the following code in
its code behind:

==================
public partial class MediaOutput : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fn = Request.QueryString["fn"];

if (string.IsNullOrEmpty(fn))
{
throw new Exception("Invalid Argument...........");
}

Response.ClearHeaders();
Response.ClearContent();

Response.ContentType = "audio/wav";

Response.WriteFile(@"D:\temp\media\" + fn);

Response.End();

}
}

============================
Then, in other page which want to reference a certain wav file in the
"D:\temp\media" folder, we no longer need to care about the physical path,
but simply use the "MediaOutput.aspx" to get the wav stream. e.g.
<a href="MediaOutput.aspx?fn=ding.wav" >play ding.wav </>
if you want to create a custom httphandler to do the work, please refer to
the following article:

http://weblogs.asp.net/cazzu/archive.../27/25568.aspx


However, as I've mentioned, if you directly point to the wav stream in the
hyperlink, the wav will be played in a new player window at
client-side(maybe media player or other player...). If you do not want to
let a new launched player to do it, you can have a look at the following
web pages:

#Playing Sounds On The Web
http://www.w3schools.com/media/media_browsersounds.asp

#Demonstration of Different Ways to Play a Sound from a Web Page
http://www.phon.ucl.ac.uk/home/mark/audio/play.htm
it demonstrate several means to play sound, you can even use javascript to
make a certain element(like <bgsoundor <embedto reference the media
stream output by the "mediaoutput.aspx" page above).

Hope this helps. If there is anything unclear, please feel free to let me
know.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 24 '06 #2
Steven
Thanks for your reply. Your advice and links you sent were very helpfull.

I implemented your solution using the MediaOutput.aspx page. And that
works. Thanks

However if the MsgFile field, which is passed in MediaOutput.aspx?fn={0},
has a full path e.g. c:\FP\audio\1.wav then the Hyperlink is not active. It
appears that the ':' is not allowed in the {0} value. If it contains a
partial path without the c: part (specifically the ':') it works.
What is wrong with ':' in the QueryString parameter?

Thanks
Morris
"Steven Cheng[MSFT]" wrote:
Hi Morris,

From your description, I understand your web application will display some
links on one page (through grid) and the link will point to some wav sound
so that the user can play it when click on the link. The problem is that
the wav files is in a non-virtual directory(accessible through http
address) on the server, correct?

As for this problem, I think it is doable and have several means. I'd like
to confirm following things first:

1. Are you developing through ASP.NET 1.1/VS 2003 or ASP.NET 2.0/VS 2005?

2. As for the media file(wav), how do you want to play it to client user,
among the following options:

** let the client user directly link to the media and the browser will
choose a player on the client to play it.

** embed some activex or sound tag in web page and use let the browser to
play it, thus , the client will not launch a separate player when user
click the link.
As for the wav file linking problem, I don't think we can directly use the
physical path(like c:\media\.....) because this path is not recommend for
internet application. also, the "c:\media\" physical path is only valid to
the server machine, since the page is finally displayed in client browser,
the browser will try locating the file on the client machine's disk and
won't be able to get the file.
To resolve this, I suggest you consider the following means:

1)Create an ASP.NET web page or HttpHandler which will programmtically read
the file from the non-web folder and then write it out as response stream.
e.g.

suppose the page's name is "MediaOutput.aspx", we add the following code in
its code behind:

==================
public partial class MediaOutput : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fn = Request.QueryString["fn"];

if (string.IsNullOrEmpty(fn))
{
throw new Exception("Invalid Argument...........");
}

Response.ClearHeaders();
Response.ClearContent();

Response.ContentType = "audio/wav";

Response.WriteFile(@"D:\temp\media\" + fn);

Response.End();

}
}

============================
Then, in other page which want to reference a certain wav file in the
"D:\temp\media" folder, we no longer need to care about the physical path,
but simply use the "MediaOutput.aspx" to get the wav stream. e.g.
<a href="MediaOutput.aspx?fn=ding.wav" >play ding.wav </>
if you want to create a custom httphandler to do the work, please refer to
the following article:

http://weblogs.asp.net/cazzu/archive.../27/25568.aspx


However, as I've mentioned, if you directly point to the wav stream in the
hyperlink, the wav will be played in a new player window at
client-side(maybe media player or other player...). If you do not want to
let a new launched player to do it, you can have a look at the following
web pages:

#Playing Sounds On The Web
http://www.w3schools.com/media/media_browsersounds.asp

#Demonstration of Different Ways to Play a Sound from a Web Page
http://www.phon.ucl.ac.uk/home/mark/audio/play.htm
it demonstrate several means to play sound, you can even use javascript to
make a certain element(like <bgsoundor <embedto reference the media
stream output by the "mediaoutput.aspx" page above).

Hope this helps. If there is anything unclear, please feel free to let me
know.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Aug 24 '06 #3
Hello Morris,

The url and ":" char issue is due to the restriction of characters allowed
in url. If we wan t pass any data in querystring which will contain some
potential particular characters(not allowed in URL), we'd better Urlencode
it before send it. For example, we can use the Server.UrlEncode to encode
our file path before bind it to link. e.g.
================================
<asp:TemplateField>
<ItemTemplate>
<a href="<%# "TargetPage.aspx?fn=" +
Server.UrlEncode(Eval("FilePath").ToString()) %>">link to media</a>
</ItemTemplate>
</asp:TemplateField>
===============================

Also, at the TargetPage.aspx, you do not need to explicitly decode it,
ASP.NET runtime will do it for you, you can simply read out the querystring
value as normal.

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 25 '06 #4
Steven
So far what you have helped with is working.
I am using the response.writefile(@filename) to play the audio .wav file
with the URLEncode.

Now I have an issue that when the Media player starts up to play the file
some time it gives an error that it could not play the file / may not have
the codecs needed to play the file, which is a .wav file. Error: cood1199.
Sometime it does play the file fine but thats not consistant and I cant
reproduce it working or failing with any consistancy.

If I click on the target file in the Windows explorer to open it the Media
player always starts up and plays the file.

Also on the same topic when I click on the file in windows explorer the
Media Player display the filename that is playing. But when it does play via
the app the Media Player only displays "Media Output". How can I control
what is diaplyed in the MP?

Any direction here is appreciated. Should I post to the group for Media
Player? If so which one is that?

And finally a question on Response.Write(). I use it to display an error
message via a Try/Catch loop around the response.writefile() in the event
that the file is not found. That works but my question is how can I get
response.write() to open a new browser window instead of writing to the same
explorer window that issued the request?

--
Thanks
Morris
"Steven Cheng[MSFT]" wrote:
Hello Morris,

The url and ":" char issue is due to the restriction of characters allowed
in url. If we wan t pass any data in querystring which will contain some
potential particular characters(not allowed in URL), we'd better Urlencode
it before send it. For example, we can use the Server.UrlEncode to encode
our file path before bind it to link. e.g.
================================
<asp:TemplateField>
<ItemTemplate>
<a href="<%# "TargetPage.aspx?fn=" +
Server.UrlEncode(Eval("FilePath").ToString()) %>">link to media</a>
</ItemTemplate>
</asp:TemplateField>
===============================

Also, at the TargetPage.aspx, you do not need to explicitly decode it,
ASP.NET runtime will do it for you, you can simply read out the querystring
value as normal.

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 29 '06 #5
Thanks for your reply Morris,

As for the occasional cood1199 error, it is likely that the response stream
contains incorrect binary data (which is not audio/wav stream), then the
client media player will surely report error against the data.

You can use some http/tcp trace tools to capture the http response message
to see whether the response message doesn't contain correct audio/wav data
at those error requests. The SOAP Toolkit 3.0 contains a trace utility
which can help capture http request/response message.

#SOAP Toolkit 3.0
http://www.microsoft.com/downloads/d...0DD-CEEC-4088-
9753-86F052EC8450&displaylang=en
for your further question:

====================
And finally a question on Response.Write(). I use it to display an error
message via a Try/Catch loop around the response.writefile() in the event
that the file is not found. That works but my question is how can I get
response.write() to open a new browser window instead of writing to the
same
explorer window that issued the request?
=====================

I'm afraid this is not supported, because our MediaOutput page is suppose
to return binary audo/wav data only and we should not use response.Write to
flush out any non-wav data(text, xml ....), this will violate the
"audio/wav" contenttype we set in the code. For such scenario, I suggest
you consider the following approach:

=======================
try
{

...............
Response.ClearHeaders();
Response.ClearContent();

Response.ContentType = "audio/wav";
Response.AddHeader("Content-Disposition",
"attachment;filename=ding.wav");

Response.WriteFile(@"D:\temp\media\" + fn);

Response.End();
..................

}
catch (Exception ex)
{
Response.Redirect("errormedia/error_sound.wav");
}

=========================

instead of writeout text, you can redirect the request to an existing wav
file in the web application folder which contains the sound about error so
that the client will get the error media and play it. Do you think it
doable in your scenario?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.




Aug 29 '06 #6
1. With the Media error. The same file will work and then not work so how can
that be a data error?

2. With the Error message. What I did was change the context in the catch
block to "text/HTML" and then write out an error message.
=======================
catch (Exception ex)
{
Response.ContentType = "text/HTML";
Response.Write("Error occurred <br>");
Response.Write(e.messgae);
Response.Write("Click back to try again");
}
======================
This works but I want to send the error message to a new IE window and leave
the original window open (like a pop up message box). so I dont have to
tell the user to "Click Back" to get to the original page in IE. They can
just close the error message window and still have the original Page in IE
that started the process.

--
Thanks
Morris
"Steven Cheng[MSFT]" wrote:
Hello Morris,

The url and ":" char issue is due to the restriction of characters allowed
in url. If we wan t pass any data in querystring which will contain some
potential particular characters(not allowed in URL), we'd better Urlencode
it before send it. For example, we can use the Server.UrlEncode to encode
our file path before bind it to link. e.g.
================================
<asp:TemplateField>
<ItemTemplate>
<a href="<%# "TargetPage.aspx?fn=" +
Server.UrlEncode(Eval("FilePath").ToString()) %>">link to media</a>
</ItemTemplate>
</asp:TemplateField>
===============================

Also, at the TargetPage.aspx, you do not need to explicitly decode it,
ASP.NET runtime will do it for you, you can simply read out the querystring
value as normal.

Hope this helps.
Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 29 '06 #7
Thanks for your reply Morris,

If the problem will occur against the same file and response stream
randomly, it's quite hard to determine the actual cause, is it specific to
a certain client?

BTW, if as for displaying error message or open in a new browser windows,
you can consider output some javascript code to show a message box or open
a new browser window pointing to another error page. for example:

=======================
...............
}
catch (Exception ex)
{

Response.ClearHeaders();
Response.ClearContent();

Response.ContentType = "TEXT/HTML";

Response.Write("<script language='javascript'
>alert('error.....');</script>");
Response.Write("<script language='javascript'
>window.open('errorpage.aspx');</script>");
Response.End();
}
...................
==========================

However, this will work only when the user directly click on the link to
our MediaOutput page's url.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 30 '06 #8
Hi Morris,

Have you got any further progress on this issue or does the new suggestion
in my last reply also helps a little?

If there is anything else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 1 '06 #9
Hi Steven,

I think I've been doing stuff similar to Morris, I got stuck however
because I seem to have no fastforwarding / rewind functionality in my
Windows Media Player control! I'm using the OBJECT tag to include the
WMP control in my web page to play streamed WAV files as illustrated
below.

* ASP.NET 2.0
* VS 2005
* Windows Media Player 10.00.00.3802 and 9.00.00.2980

______________________________
Requirements:

I want to build a web page with an integrated Audio Player that
-1- can play (streamed) WAV files
-2- has Play / Stop / Pause / FastForward / Rewind buttons
-3- prevents the user from downloading the WAV file
-4- does not cache the audio file

My first choice was the Windows Media Player control in internet
explorer, simply because I don't need support for browsers other than
IE, and it seems quite easy at first sight to add my own UI to the
player, controlling the WMP control with some VBScript for instance. It
should become part of an ASP.NET solution anyhow...

______________________________
I tried this:

An audioPlayer.aspx file that generates a web page with a Windows Media
Player control. The URL parameter of the WMP control is a
streamAudio.aspx file. The streamAudio.aspx file streams the WAV file to
the browser (streamAudio.aspx will pick the file name from the request
eventually). I thought this already solves -3- and -4- because the
client has no direct access to the WAV file, only to a binary stream.
This is the code:
===== audioPlayer.aspx =====
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>audioPlayer</title></head>
<body>
<form id="form1" runat="server">
<div>
<object id="Player" height="45" width="220"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<param name="autoStart" value="False" />
<!--param name="uiMode" value="invisible" /<!-- hide later, when it
works... -->
<param name="URL" value="audioStream.aspx" />
</object>
<input type="BUTTON" name="BtnPlay" value="Play" onclick="StartMeUp()"
/>
<input type="BUTTON" name="BtnStop" value="Stop" onclick="ShutMeDown()"
/>
<input type="BUTTON" name="BtnForward" value="fwd" onclick="ffw()" />
<script type="text/vbscript">
<!--
Sub StartMeUp ()
form1.Player.controls.play()
End Sub
Sub ShutMeDown ()
form1.Player.controls.stop()
End Sub
Sub ffw()
If form1.Player.controls.isAvailable("FastForward") Then
MsgBox "found fastforward"
form1.Player.controls.fastForward()
Else
MsgBox "didn't find fastforward"
End If
End Sub
-->
</script>
</div>
</form>
</body>
</html>
===== audioStream.aspx =====
<%@ Page Language="VB" Src="~/audioStream.aspx.vb"
Inherits="MyNS.audioStream"%>
===== Code-behind page audioStream.aspx.vb =====
Imports Microsoft.VisualBasic
Namespace MyNS
Partial Public Class audioStream
Inherits System.Web.UI.Page

Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "audio/wav"
Response.WriteFile("C:\myfile.wav")
Response.End()
End Sub
End Class
End Namespace

______________________________
Result:

When I click the fwd button

on Windows XP SP2, WMP 10.00.00.3802:
all clicks: "didn't find fastforward"

on Windows 2000 advanced Server, WMP 9.00.00.2908:
first click: "found fastforward" and fast forwarding really works
all subsequent clicks: "didn't find fastforward"

______________________________
Questions:

[1] fastforward in WMP
Does anyone know why the fastforward is disabled? Is this problem caused
by my specific files (WAV files, but it also fails for mp3, and I heard
others complain even about WMV!), or is it caused by WMP? I mean, are
there some characteristics of audio files that make it impossible for
any audio player to fastforward them, or is this just a shortcoming
(bug!?) of Windows Media Player?

This makes me think WMP is unreliable and not the way to go. How can I
expect my customer to run WMP 10.00.00.2334.11.22.s.o.m.e.n.r.0.1.2.3 on
Windows XP SP2 with this and this and that, and nothing else because
otherwise his player will not be fully functional? It seemed like quite
a cool control initially but I'm starting to have some doubts now...

[2] Caching of streams
I'm not quite sure about the caching. If I stream the WAV file to the
client, is the stream cached somehow on the client? Simply put: If the
client closes all the browsers, and all sessions have expired, is there
any way that he can find and playback the audio on his machine (from tmp
internet files or whatever location)?

[3] What are the alternatives to realize the above in a reasonably
simple way: An audio player (preferably with customizable UI) that can
receive streamed WAV files (or possible a converted file format, if WAV
is not suitable), with play/pause/stop/fastforward/rewind functionality.
No Quicktime or Realplayer... Using .NET 2.0 and VB 2005 though!

Many Thanks in advance!

Guido

*** Sent via Developersdex http://www.developersdex.com ***
Sep 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
I would like to have one column in my DataGrid that content acts as a hyperlink. In addition to that I would like that the content is databound to a DataSet source. If I create a hyperlink...
12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
1
by: Martin Dew | last post by:
I have a HyperLinkColumn inside my Databound grid on a page, I have been using the URL Field property set to a field name in my bound data, and then using the URL Format String as...
6
by: Graeme | last post by:
Hello I thought if I linked a datagrid column to a field containing something like this ... <a href="http://www.google.com" target="_blank">http://www.google.com</a> ... that it might appear...
1
by: carlor | last post by:
Hi there, I have a datagrid that is bound to a datasource. The grid has a hyperlink column and I want to generate the URL using the URL Field and URL Format String fields in the Property...
2
by: Fabrice | last post by:
Hello, First, thanks to felix for his answer. But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble : Always in the road whith my Datagrid and my ItemTemplate...
2
by: david | last post by:
I have a HyperLink Column , View, in DataGrid, which link to URL Field, called URLQuery. In codebehind, I have dsResource.Tables("Resource4Spec").Columns.Add("URLQuery",...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
6
by: homevista | last post by:
PART III: Putting things together In part I we examined the modem to verify that it supported voice. If so, we took a note about the voice data format that we would use. In the second part, we...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.