This project has moved. For the latest updates, please go here.

Streaming sound from internet / server?

Aug 19, 2009 at 8:17 PM

Would it be possible to stream a sound file from the internet / server into my application?
I've tried to use a http URL as a string to feed the player, but Visual Studio says the following:

Argument exception was unhandeled. Does not support URL-format
on this line:

Dim mp3Reader As WaveStream = New Mp3FileReader(fileName)

 

How can I make this work?
The purpose for this is that I'm trying to create an small Spotify-like application which acts as a client, connecting to a database where sound files are stored as string values. Those values are then passed into the sound player.
And the values are the path of the sound files's location.

How should I approach this? Would I need to create a buffer of some sort? What about playing the sound file as soon as possible? Would that mean having the streaming and sound playback running in separate threads?
This sounds a bit more advanced that I've tried previously but I'm really keen on trying to get this to work :)

A different thing would be uploading sound files to the path as I've downloaded from. But that would probably be a different story I guess.

Any help would really be appreciated! :)

 

Editor
Aug 19, 2009 at 10:07 PM

Hi Kenny,

I've replied to your question on Stack Overflow as well but for any one else looking for an answer to this see this question and answer:

http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c/225260

Cheers,
Sebastian

Aug 24, 2009 at 12:20 PM

Hi again :)

Could you please revisit the thread on StackOverflow? The example shown is in C# and I cannot manage to convert it properly to VB.NET.
Actually, it looks like that solution provided there is a mix of the function from the nAudio Examples and the HttpWebStream function. But the code isn't converted correctly, So I get an error message saying that:

"Value of type 'System.IO.MemoryStream' cannot be converted to 'String'"
This is at line "New BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(New Mp3FileReader(ms)))"

Coordinator
Aug 24, 2009 at 2:35 PM

are you working with the latest source code? the constructor for Mp3FileReader that takes a stream was added in Dec 2008

Mark

Aug 24, 2009 at 6:41 PM

Clearly I was not. But the code has changed a bit and I get alot of errors after trying to convert the code. E.g the Mp3FileReader was way smaller before and I actually put the functions etc inside the main window form (which I know is a terrible no-no), but now I thought I'd scatter the code a bit into separate Classes.vb files and I keep getting these errors, like "Property 'AvarageBytesPerSecond' is 'ReadOnly'" and "Property 'BitsPerSample' is ReadOnly"

I don't know if the conversion tool messes up some things or if it's just me, but there are alot of these similiar errors. You don't be any chance have a codebase for vb.net, Mark?
Before, it all worked atleast. With my crappy code converted directly by http://www.developerfusion.com/tools/convert/csharp-to-vb/

But I guess taking time to implement the newest source code is worth the time.

Aug 26, 2009 at 5:05 AM

Wait, let me get this straight? Is it possible for me to create a VB.NET project and just import the .cs files you've created and use the classes from that? I don't have to convert the code to VB? That would be awesome indeed

Editor
Aug 27, 2009 at 1:57 AM

Hi Kenny,

Not sure what happened to my post but it seems to have gone astray. You can't just add the .cs file to a VB.Net project - what you can do is build a small C# project which will export a single .dll that you can then reference in your VB.Net project instead. Once a .Net library is built it can be consumed by any .Net language.

Cheers,
OpenSebJ

Aug 28, 2009 at 3:24 PM
Edited Aug 29, 2009 at 12:14 PM

Edit: I think I'll just try to do this with C# instead :)

Ok, so I downloaded the latest nAudio project file, which is in C#. And i built this, which produced a dll, which was probably produced from before anyway.
Then I deleted my existing reference dll in the vb.net project and added the newly build dll.

What happens is that I can type e.g "naudio.wave" and then see all of the classes within the dll, such as "Mp3FileReader" and such.
But if I press punctuation, all I get is this:

Equals
Null
ReferenceEquals
Synchronized

This is the same no matter what class I try to access.
So the code fails at certain points, like accessing the "NAudio.Wave.MeteringStream.StreamVolumeEventArgs"

In the demo, this class is not in the Wave section, but I moved it there and changed the namespace to Naudio.Wave to make it easier to access.
And this seems to work just as good as the other classes in the nAudio.Wave namespace.
But the code fails with the following error message: "Type 'MeteringStream.StreamVolumeEventArgs' is not defined"

Even though I know it's there. Is this normal? I can also type "Naudio.Wave.MeteringStream" and intellisense says it's a class and all. But pressing punctiation gives the same options as stated above. I also tried to convert the c# code from the MeteringStream.cs into VB and make it it's own vb class.
Which worked well. I can access the StreamVolumeEventArgs, no error message in Visual Studio. But building the project and trying to play something returned an error saying "Reference object is null" or something.