×

Discussion Board

Results 1 to 7 of 7

Thread: Stream an MP3

  1. #1
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Stream an MP3

    Is there a way to stream a MP3?

    Jamendo is returning their Radio Streams as mp3 file ( http://developer.jamendo.com/v3.0/radios/stream ), the file opens, but hangs at 0 byte and no music was heard. Tried on device (311) without luck.
    Already tried removing http:// and adding rtsp:// - not working :'(
    Any ideas from the audience?

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Stream an MP3

    I do not know, it works for me.
    What I tried is getting the example from your link (so streaming.radionomy.com/JamRock), and wrote a downloader for it:
    Code:
    Socket s=new Socket("streaming.radionomy.com",80);
    OutputStream os=s.getOutputStream();
    os.write("GET /JamRock HTTP/1.0\r\n\r\n".getBytes());
    InputStream is=s.getInputStream();
    String str="";
    while(true)
    {
        str+=(char)is.read();
        if(str.endsWith("\r\n"))
        {
            if(str.length()==2)break;
            System.out.print(str);
            str="";
        }
    }
    byte b[]=new byte[4096];
    int cnt=500000;
    FileOutputStream fos=new FileOutputStream("test.mp3");
    while(cnt>0)
    {
        int l=is.read(b);
        fos.write(b, 0, l);
        cnt-=l;
    }
    fos.close();
    s.close();
    actually it is desktop code (Socket, FileOutputStream, System.out), but I really believe that Java ME behaves similarly.
    The result was playing well on a Nokia N8 (I have no Asha devices, so that may be still different).
    The only tricky thing is that InputStream.read reads some (kilo)bytes only, so passing a few megabytes array to it does not mean that you get few megabytes of data. DataInputStream has a readFully method, just I did not want to mix that here.

  3. #3
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Re: Stream an MP3

    Thank you, but this kind of code works not in an Series40 WebApp.

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Stream an MP3

    Yes, now I see that it is a WebApps question.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Stream an MP3

    I assume you try http://www.developer.nokia.com/Commu...eo_or_audio.3F, so mwl.loadURL. But what happens if you directly open http://streaming.radionomy.com/JamRock with the browser? Does it recognize the stream, or just tries to display it, or something else?

  6. #6
    Regular Contributor
    Join Date
    Jun 2010
    Posts
    161

    Re: Stream an MP3

    yes, it tries to download but then is stuck at 0 bytes.

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: Stream an MP3

    A thing with the code below is that it prints out the response header:
    HTTP/1.0 200 OK
    Accept-Ranges: none
    Content-Type: audio/mpeg
    icy-br:128
    ice-audio-info: bitrate=128;samplerate=44100;channels=2
    icy-br:128
    icy-description:Jamendo Radio by Nicole
    icy-genre:Rock
    icy-name:Jamendo Rock Radio
    icy-pub:1
    icy-url:http://www.jamendo.com
    Server: Icecast 2.3.3-kh8
    Cache-Control: no-cache
    Pragma: no-cache
    Expires: Mon, 26 Jul 1997 05:00:00 GMT
    as you can see, it is HTTP-ish, but does not contain Content-Length. That is why a simple browser can not download it (HTTP/1.0 specs are here: http://www.w3.org/Protocols/rfc1945/rfc1945, sections 7.2 and 7.2.2 deal with content and its length).
    An alternative you can experiment with is downloading chunks of the stream from code, and offer the pieces to loadURL. However JavaScript is probably not enough for this, I think some server would be required.

Similar Threads

  1. Replies: 1
    Last Post: 2007-11-17, 01:04
  2. Stream from RMS
    By kewldeep in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2006-08-24, 00:47
  3. Stream h.263 with mmf
    By henranto in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2006-06-30, 10:22
  4. Sending a bit stream instead of a string stream by means of descriptors
    By RyanSantos in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2006-01-17, 05:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •