locked
Streaming sound to mobile browser RRS feed

  • Question

  • User1939951552 posted

    Hi,

    Need to stream stored audio (stored in database) to windows mobile browser. Anyone an idea how to do it?

     BTW: Accomplished it for the standard IE by means of the following construction (thanks to Lance Zhang):

    <object id='objAudio' width="320" height="44" classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/ mplayer/en/nsmp2inf.cab#Version=5,1,52,701' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>

    <embed type='application/x-mplayer2'pluginspage="http:/www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx" id='mediaPlayer' name='mediaPlayer' displaysize='4' autosize='0' bgcolor='darkblue' showcontrols='0' showtracker='1' showdisplay='0' showstatusbar='0' videoborder3d='0'
    width="320" height="44">
    </embed>
    Perhaps just need the correct CLSID...

    thx, Gerard

    Tuesday, August 19, 2008 8:28 AM

Answers

  • User1009273304 posted

    use httphandler for this purpose...like the following one

     

     

    public class Streaming : IHttpHandler
    {

        public Streaming()
        {
        }

        public void ProcessRequest(HttpContext context)
        {
           
               //here read ur file from database   

     

                   // Add HTTP header stuff: cache, content type and length       
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetLastModified(DateTime.Now);

                    context.Response.AppendHeader("Content-Type", "audio/mp3");
                    context.Response.AppendHeader("Content-Length", length.ToString());

                    // Read buffer and write stream to the response stream
                    const int buffersize = 16384;
                    byte[] buffer = new byte[buffersize];
                   
                    int count = fs.Read(buffer, 0, buffersize);
                    while (count > 0)
                    {
                        if (context.Response.IsClientConnected)
                        {
                            context.Response.OutputStream.Write(buffer, 0, count);
                            count = fs.Read(buffer, 0, buffersize);
                        }
                        else
                        {
                            count = -1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
              
            }
        }

        public bool IsReusable
        {
            get { return true; }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 21, 2008 5:48 AM
  • User-22218653 posted

    thanks russell786....

    its a nice example for the beginners and this post also helps me lot. :D
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 25, 2008 1:12 PM

All replies

  • User1009273304 posted

    use httphandler for this purpose...like the following one

     

     

    public class Streaming : IHttpHandler
    {

        public Streaming()
        {
        }

        public void ProcessRequest(HttpContext context)
        {
           
               //here read ur file from database   

     

                   // Add HTTP header stuff: cache, content type and length       
                    context.Response.Cache.SetCacheability(HttpCacheability.Public);
                    context.Response.Cache.SetLastModified(DateTime.Now);

                    context.Response.AppendHeader("Content-Type", "audio/mp3");
                    context.Response.AppendHeader("Content-Length", length.ToString());

                    // Read buffer and write stream to the response stream
                    const int buffersize = 16384;
                    byte[] buffer = new byte[buffersize];
                   
                    int count = fs.Read(buffer, 0, buffersize);
                    while (count > 0)
                    {
                        if (context.Response.IsClientConnected)
                        {
                            context.Response.OutputStream.Write(buffer, 0, count);
                            count = fs.Read(buffer, 0, buffersize);
                        }
                        else
                        {
                            count = -1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
              
            }
        }

        public bool IsReusable
        {
            get { return true; }
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 21, 2008 5:48 AM
  • User-22218653 posted

    thanks russell786....

    its a nice example for the beginners and this post also helps me lot. :D
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 25, 2008 1:12 PM
  • User1939951552 posted

    Works fine! Thanks a lot. Had some problems with deployment on IIS6.0, but found the answer here: http://forums.asp.net/p/1107193/1701216.aspx

    Gerard

    Wednesday, August 27, 2008 10:53 AM