tags:

views:

269

answers:

1

Hi, I noticed in the NAudio Demo from the latest version of NAudio that if Filename is empty, then it opens a fileopendialog. So if I paste a http link in that window and click OK, I've noticed that the FileName string looks something like this:

"C:\Users\User\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5\2FO1NTK2\20s[1].mp3"

How does this exactly happen? I don't want an OpenFileDialog because the path I want to play is already stated elsewhere. And in my case, I use a string which looks something like this "http://domainname.com/file.mp3"

This creates an error stating that URL is not supported. So I guess there's something I'm missing here?

Edit: Inserting the PlayMp3FromUrl gives me this error in WaveOut:

'NAudio.Wave.WaveOut' does not contain a constructor that takes '3' arguments' This is at line "using (WaveOut waveOut = new WaveOut(0, 500, null))" I tried to just remove all of the arguments, leaving it ()), and that compiles. But the sound playback seems to start for a microsecond or something. And then everything freezes. I've tried with various arguments and none seem to work. I guess it's got something to do with the arguments?

A: 
"http:\www.domainname.com/file.mp3"
      ↑

Does it work with // ?


Using PlayMp3FromUrl from this SO question:

PlayMp3FromUrl("http://www.domainname.com/file.mp3");
dtb
Oh, I wrote incorrectly. The URL path IS http:// :)
Kenny Bones
What I'm really wondering is that one I've pasted the http URL in the fileopendialog, some code somewhere must create a download stream or something. Since the filename string ends up with a path in Temporary Internet files.
Kenny Bones
I believe `Temporary Internet Files` is the location where Internet Explorer stores its temporaray files (a.k.a. "cache").
dtb
Yes i know, but HOW does that happen?? I can't see it happening directly during debugging. So could it be something within OpenFileDialog? A version of NAudio from 2008 included the possibility to work with URL paths, and I downloaded the most reasent one.
Kenny Bones
Have you looked at this? http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c
dtb
Yup, I have. The person developing NAudio added this to the source code in 2008. But still it seems as though it's OpenFileDialog it uses to actually create the stream or something. It's weird, because the Mp3FileReader.cs has two constructors and one is for using a Stream. It just can't manage to get to use it without FileOpenDialog
Kenny Bones
Looking at `Mp3FileReader` in revision 28568 there's no call to a FileOpenDialog. It operates on the stream directly. The other constructor just opens the file for reading using `System.IO.File.OpenRead`. OpenRead works with local files only. So maybe the functionality you're looking for is in some other class?
dtb
Its in the AudioPlaybackForm.cs the playbutton checks to see if FileName is empty or not. If it is, it calls "toolStripButtonOpenFile_click", which opens the filedialog and sends the results to the string "fileName" and uses that. What I'm doing is exactly the same, only, my string is set via a textbox.text value. The URL is a typical http:// path.It's basically what's causing the download stream to begin I'm interested in. I can't figure out how that's happening by using step in. FileName is suddently populated with a path to Temporary Internet files.
Kenny Bones
This seems to be a feature of the OpenFileDialog: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/329db03d-a774-405e-aa6a-db5db2473e9a
dtb
I'd recommend you use a WebRequest to download the file yourself or to stream it as shown in the other SO question.
dtb
Ah, so it wasn't included in the NAudio code :) That explains a lot, I thought there was a check or something that starts the download if it was a http url :)
Kenny Bones
Forgive me for being an absolute idiot, but how do I actually use the PlayMp3FromUrl ?If I just add it in the Mp3FileReader.cs as instructed, that portion isn't even used. It goes right to "File.OpenRead" and that gives me an error message saying that URLs aren't supported. Btw, I do think that the same functionality that was created by a user at the previous link you gave, is in the Mp3FileReader.cs now. It's just, I don't know how to make the code go there instead of opening a local file. I've updated the first post.
Kenny Bones
Uhm, PlayMp3FromUrl is a static method. Just put it somewhere (you don't have to modify the NAudio source code for this) and invoke it with your URL. I've updated my answer. I don't see any code in Mp3FileReader that involves a WebRequest.
dtb
Oh I see, the PlayMp3FromUrl passes the download stream further into the Mp3FileReader.cs. But I guess "WaveOut" has changed since the code PlayMp3FromUrl was written. I get an error message saying:'NAudio.Wave.WaveOut' does not contain a constructor that takes '3' arguments'This is at line "using (WaveOut waveOut = new WaveOut(0, 500, null))" I tried to just remove all of the arguments, leaving it ()), and that compiles. But the sound playback seems to start for a microsecond or something. And then everything freezes. I've tried with various arguments and none seem to work.
Kenny Bones
Does it work if you use Mp3FileReader with a local file?
dtb
Yes, if I just pass a local mp3 file directly to the Mp3FileReader it works as intended. But through the PlayMp3FromUrl fails with that error message. And doesn't compile
Kenny Bones
Wouldn't it possible to mix the code from PlayMp3From URL into the Mp3FileReader somehow? Would be nice to make the audio automatically play no matter if the source is local or via web.
Kenny Bones