Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Datagrid Hyperlink field to play file system wave file help. (http://www.velocityreviews.com/forums/t366285-datagrid-hyperlink-field-to-play-file-system-wave-file-help.html)

=?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= 08-24-2006 01:17 AM

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

Steven Cheng[MSFT] 08-24-2006 12:12 PM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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 <bgsound> or <embed> to 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.



=?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= 08-24-2006 06:28 PM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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 <bgsound> or <embed> to 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.
>
>
>


Steven Cheng[MSFT] 08-25-2006 02:48 AM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.


=?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= 08-29-2006 12:38 AM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.
>
>


Steven Cheng[MSFT] 08-29-2006 07:52 AM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.











=?Utf-8?B?TW9ycmlzIE5ldW1hbg==?= 08-29-2006 02:54 PM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.
>
>


Steven Cheng[MSFT] 08-30-2006 08:52 AM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.


Steven Cheng[MSFT] 09-01-2006 11:43 AM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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.


Guido Helmers 09-11-2006 09:51 PM

RE: Datagrid Hyperlink field to play file system wave file help.
 
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 ***


All times are GMT. The time now is 05:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.