This project has moved and is read-only. For the latest updates, please go here.

webradio streaming

Mar 17, 2011 at 10:53 PM

how can i stream from a webradio like technobase.fm i am able to get the stream and write it into a file but the decoder doesn t work fine 4 me. So i can t play this realtime from web. It comes in with

 

File1=http://listen.technobase.fm/tunein-dsl-pls
Title1=TechnoBase.FM - MP3 128k - High Quality - (DSL/Cable)

 

But i can t decode this... here is the code does anyone knows what i have to change?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using NAudio;
using NAudio.Wave;

namespace LiveStreamRadio
{
    public partial class Working : Form
    {
        public Working()
        {
            InitializeComponent();
        }

       private void button1_Click(object sender, EventArgs e)
        {
            PlayMp3FromUrl();
        }
        public Stream memstream = new MemoryStream();

        public void PlayMp3FromUrl(/*string url hier würde noch url mitgegeben werden.*/)
        {
            baWork.RunWorkerAsync();
           
        }

        private void backStream_DoWork(object sender, DoWorkEventArgs e)
        {
            using (Stream stream = WebRequest.Create("http://listen.technobase.fm/tunein-dsl-asx").GetResponse().GetResponseStream())
            {
                byte[] buffer = new byte[32768];
                int read;
                while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    
                    memstream.Write(buffer, 0, read);
                    Console.WriteLine("Written" + memstream.Length);
                }
            }
         }

        private void Working_Load(object sender, EventArgs e)
        {
            backStream.RunWorkerAsync();
        }

        private void baWork_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                Console.Beep(500, 1000);
                memstream.Position = 0;
                using (WaveStream blockAlignedStream =
                    new BlockAlignReductionStream(
                        WaveFormatConversionStream.CreatePcmStream(
                            new Mp3FileReader(memstream))))
                {
                    using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                    {


                        waveOut.Init(blockAlignedStream);
                        waveOut.Play();
                        while (waveOut.PlaybackState == PlaybackState.Playing)
                        {
                            System.Threading.Thread.Sleep(100);
                            //this.Text = memstream.Length.ToString() + "   " + blockAlignedStream.Position.ToString();
                            Console.WriteLine(memstream.Length + "   " + blockAlignedStream.Position);
                        }

                    }
                }
            }
            catch (Exception ex) {
                Console.WriteLine("ERROR" + ex.Message);
                if (ex.Message == "Not a recognised MP3 block") { memstream.Dispose(); memstream = new MemoryStream(); }
            }
        }

        private void baWork_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            baWork.RunWorkerAsync();
        }
     }

}

 

so please help me !!

it would be soooo nice :)

Mar 18, 2011 at 9:08 PM

i ve got i now :)

 

 

close pls

Mar 19, 2011 at 4:30 PM

Good evening,

could you please post what the problem really was? And what was the solution you found?

I am working on the same project and i have some difficulties too. Furthermore the solution you presented applies for mp3. What if a radiostation

transmitts in wma? Do you have an oppinion?

 

Thank you in advance,

ioigoume

Mar 21, 2011 at 6:03 PM

You have to look on the header while writing