Thursday, January 1, 2009

MeRadio - A Shoutcast Radio Streaming Client for Java ME

Hello,

a new year and a new project. This time it's a Shoutcast radio streaming client for Java ME, which I started as a hobby project. I called it MeRadio. Inspired by this post to stream Shoutcast streams to the IPhone, I wanted to make such an application (MIDlet) for Java ME (J2ME). Here it is in an initial version:

The download package (links below) contains:
- a server part which consists of three files: meradio.php5, mr.xml and php.ini
- the mobile application MeRadio (Nokia and Sony Ericsson version) with its source

The Server

The file meradio.php5 has two main functions: First it delivers the radio stream URLs from mr.xml to the mobile application, second it streams the plain audio data (mp3) of a radio station to the mobile application, while stripping off useless Shoutcast headers, which cannot be understood by Java ME.

When you want to install this server on your webspace, php must be supported. Maybe the php.ini is also needed, which sets the property "allow_url_fopen = on". This is needed for customers of 1und1. And maybe the file extension php5 doesn't work for you. Then you should rename meradio.php5 to meradio.php. The file mr.xml is an XML formatted document containing some predefined radio stations mostly taken from the radio list of Ninj's Virtual Radio Symbian application (http://www.ninj.com/vradio/vr_list.xml). Put all 3 files into the same directory of your webspace.

Test the service using a webbrowser:
- Get the radio list using this URL: http://yourhostname/meradio.php5?rlist=1
- Hear the stream of a radio e.g.using this URL: http://yourhostname/meradio.php5?play=http://sc3.radioseven.se:8500/&clientid=123234324

The php will stop executing after 24 minutes to limit the traffic on the server and on the phone. You can adjust this value according to your needs.

The Mobile Application

Select the Nokia or Sony Ericsson version of MeRadio and simply install MeRadio.jar to your Java enabled phone. During the first start you will be advised to set the URL to meradio.php5 properly. Some Nokia devices need a port number after the hostname, otherwise an invalid locator exception might be thrown. This URL can be entered in the settings menu. Then you can click on Genres, which loads the genres (and radios) from the mr.xml file using meradio.php5. This may take some seconds, especially on Sony Ericsson phones. Then you can choose a genre and select a radio stream of interest. Now you should be able to hear the selected stream with very few or even no annoying gaps that often occur on other streaming solutions based on Java ME.

Here is the download link for the current version 0.2a:

-FileFactory:
MeRadio0.2a.zip

-MegaUpload:
MeRadio0.2a.zip


Version 0.2 introduces these updates:
- Radio list is persistently saved in the RMS (radio list doesn't need to be fetched from the server everytime the MIDlet starts)
- Radio list can be updated when necessary
- Different versions of MeRadio for Nokia and Sony Ericsson phones, as these devices support different streaming mechanisms
- Small updates to meradio.php5 and new radios (Techno) in mr.xml

I have successfully tested MeRadio on a Sony Ericsson W850i and on a Nokia 3120 classic phone (S40). You can change the source as you wish and play with it. Bug reports are always welcome as this is a new project.

Have fun with it and a happy new year
Makube

PS.:
Here are the download links for the old versions:

Version 0.2:

- FileFactory: MeRadio02_all.zip

- MegaUpload: MeRadio02_all.zip

Version 0.1:

- FileFactory: MeRadio01_all.zip

- MegaUpload: MeRadio01_all.zip


69 comments:

Joshua said...

Well this is an awesome idea! Keep up the good work.

I tried this on a Samsung Instinct on Sprint and it's a no go. I've fixed my security settings so that it can access the audio API but I always get an error, even with streams I added to the xml myself.

There are a few seconds of data transfer and then nothing. After about a minute, this error pops up:
java.io.IOException: bad url

I love the idea, but unfortunately it doesn't work on my phone.
Thanks!

Makube said...

Hi Joshua,
thanks for trying the solution and reporting back. Feel free to adapt the source codes as you wish. Samsung mobiles always had many problems with Java ME APIs. Especially the progressive download feature (streaming) should be natively supported which often isn't the case. But this is also true for a lot of Nokia phones with Symbian OS.

Best
Makube

Kartoshka said...

Really good idea. has been looking for it for a while.

So i tried it and downloaded the app to my nokia 6280 mobile, and while i can access the genres/settings/about/exit menu, i can't submit address of meradio.php5 in it, it just doesn't react to save command.

Makube said...

Hi Kartoshka,

thats strange. An alert should pop up after pressing save in the settings menu to confirm this operation. I will take a look at it again. On my phones it works flawlessly. If you see a bug in the code, please don't hesitate to report it here.

Best
makube

Makube said...

Little addition: I saw that your phone Nokia 6280 is quite old and I think that the streaming will not work on it, because only newer Nokias will support the needed progressive download function. Moreover playing mp3s within J2ME on those old phones might not be supported as well.

Makube

Mike said...

Anyone have a server side config that i can leech off of? You can PM me as well.

Gavin Smart said...

can I use this to log tune into shoutcast on my phone or do I have to have my own website to use it?

Makube said...

Hi, yes, you have to own a webspace with PHP. Best makube

Viktor said...

Hello, I get
Exception:
javax.microedition.media.MediaException: Failed to create player:

SE C902, what could be wrong?

Makube said...

Hi Viktor,

this error occured on my SE W850i
when I quickly switched radio stations. I suppose, the streaming meachanism in MIDP cannot handle subsequent requests without a break
of at least some seconds.

Best
Makube

Anonymous said...

in file meradio.php5, if I set Content-Length to be larger than 200000, the player responses nothing, no error, if less than 200000, it's all OK, can anyone tell me the reason? thanks very much

Makube said...

Hi, interesting find. Thank you. Yet, I cannot confirm this behaviour on my devices. What device do you have?

Best
makube

Wulida Rochman said...

many thanks Makube!
I'lll try to compile for my motorola phone. :-)

Makube said...

Hi Wulida,

that would be very nice of you. As I do not own a Motorola phone your feedback is very much appreciated.

Thanks and good luck
Makube

Maheshkanda said...

well this is really a good idea i tried it in my mobile it is working fine but there is a problem that it is taking min 15 to 20 min to buffering for playing the station is there any changes to take the buffering time to be of less than 1 or 2 min so it is going to appreciable .Here i am using N73
and here is my mail id
maheshkanda.inbox@gmail.com
i hope i will get the coding guidance and other guidance in a short time
thanks in advance
regards
maheshkanda

Red said...

Thanks to Makube for wonderful application...

Buffering is the most important one how to reduce it..

Makube said...

Hi Maheshkanda,

many thanks for trying the MIDlet.
I cannot do anything about the problem you described as most of (maybe all) Symbian / S60 phones by Nokia do not support the progressive download feature which is needed by the application. Therefore these devices buffer the incoming data until the end of the stream. However he newest, but technically inferior S40 devices support this feature. But I was very astonished that you waited so long for the music to start. You really wanted to test it :-) Many thanks again.

Makube

maheshkanda said...

When we try to play the radio by using the following code it has worked fine.

String url =serverurl+"?play="+streamurl+"&clientid=123234324";
HttpConnection con= (HttpConnection)Connector.open(url);
InputStream is = con.openInputStream();
player = Manager.createPlayer(is, "audio/mpeg");

This is the default code which given and after that I tried the following code but it thrown prefetch error and here is the code which we used.

HttpConnection con2= (HttpConnection)Connector.open(streamurl);
InputStream is2 = con2.openInputStream();
byte[] buffer = new byte[1024];
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
is2.read(buffer);
player = Manager.createPlayer(is2, "audio/mpeg");




And here I have a doubt that that why to use this much of is2.read(buffer); what it will do ,will u guide me on this

Thanks & Regards
Mahesh.k

Makube said...

Hi Maheshkanda,

the last code you provided was solution 3 in the Midlet code. It doesn't do anything useful, as you have guessed. This solution was to test, if it is possible to get shoutcast streaming without the server part. The shoutcast headers should be skipped by the many read() calls. The last read would actually return the first 1024 bytes of music. But then I would have to create player for every chunk that is fetched. That would result in the annoying gaps in the music, that other solutions have.
Therefore this solution is not recommended and it is not fully implemented as well. I really hope that S60/Symbian phones by Nokia will support the progressive download feature in the future.
But many thanks for your interest again.

Makube

maheshkanda said...

Hi,
this is mahesh Well nice to hear from you this but is there any alternate to the progressive download actually i heard that radio bee is playing on the same concept, right! why don't we together for implementing this as per the user friendly don't you mind my suggestion .

Makube said...

Hi mahesh,

there is another concept which causes the annoying hearable gaps during playback. It works that way:
The stream is read in chunks of some bytes (512 or 1024 for instance). These chunks are stored in a buffer and the Player Class in Java ME can read and play this buffer. But when the Player has reached the end of this buffer another Player instance will have to be created or the buffer has to be changed for the next song fragment to play. This switching causes the gaps. Even doublebuffering doesn't help much. The progressive download feature is the only solution for Java ME that avoids this nerving behaviour.

Best
Makube

maheshkanda said...

Hi,
Thanks for your replay actually i am trying it to be another way thats of interaction with perl script and php is there any way of solving the problem i will send the scrip in personal to your mail ID makubebukam@gmail.com

Makube said...

Hi mahesh,

thank you for your mail and your effort. However the main problem is not the server side, the client must support continous playback. Sadly we can't adapt the JVM inside our devices. Currently I don't have much time to work on new solutions for this issue. However we can discuss ideas and approaches per mail.

Thanks
Makube

Maheshkanda said...

Hi,
Thanks for replay and in your code the third one is which i used earlier as i told you that it is showing octet/stream is that means its giving the output in the form of bites which is shows in emulator test like 00 01 ... like that right if we use the two players means does we will get any result. If not means will you send me some coding regards two players which working. I will put some effort and i will do my level best for completing of this task.

Makube said...

Hi Mahesh,

I remember that I got a two player version to work. I believe it was at the end of 2006 when I experimented with that. But as the nasty gaps between the buffer switching did not disappear I decided to put the efforts on hold until a better solution is available. This solution is progrssive download. However the 2 player source should still be on my computer at work. I will search for the files next week when I'm back from vacation, ok? Basically it should work like that. One buffer is filled while the other is played. If the playing buffer has reached its end, then a switch to the other buffer should occur and so on.

Best
Makube

James said...

Hey, awesome idea, but I'm having problems getting the jar/jad application on my phone (SE C902) could you help? I've hosted the jad and jar on my webspace and when I try to get the jad it just says it is invalid.

Makube said...

Hi James,

this is strange, but not impossible though. I will recompile the Jad and the Jar again and put them in this post.
Thanks
Makube

Makube said...

Hi James,

I recompiled the sources again using the WTK and uploaded the result to www.makube.de/MeRadio0.2a.zip
Please check if it works for you now.

Best
Makube

Makube said...

Hi James again,

when you put the Jad and the Jar on your server you must set the property MIDlet-Jar-URL in the Jad properly so that it points to the the absolute filepath of your Jar. The simple "MeRadio.jar" as an entry is not sufficient. However you can also transfer the jar directly to your phone e.g. via Bluetooth.

Best and good luck
Makube

< T h i j s > said...

Hello Makube,

First of all I would like to tell you that this really is an awesome idea!

I've tried it on a Sony Ericsson C905, but unfortunately it doesn't work.

I probably am doing something wrong obviously, since I am quite a java n00b.

I've installed the JAR on my phone by sending it over with Bluetooth.

I copied the three files to my webspace, entered the correct adress in the midlet. (php.ini, meradio.php5 and mr.xml)

Then when I try go to the genres a piece of the (I presume) php source shows up, but no radio channels. Tried renaming the php5 to php, but that didn't help either.

What am I doing wrong here :-p?

Kind regards,


Thijs

Makube said...

Hi Thijs,

it seems that the address in the server field is not right. Put all 3 server files into one directory on the server.

The right address in the MIDlet has to look like: http://yourhostname:port/meradio.php5

Do not enter "php.ini" or "mr.xml" here. These files are needed by the meradio.php5 file and are accessed automatically.

You can test the server by pointing your browser e.g. Firefox
to http://yourhostname/meradio.php5?play=http://sc3.radioseven.se:8500/&clientid=123234324

Then it should work. Especially on your phone.

Please report back.
Makube

< T h i j s > said...

Well, when I try it in Firefox I get the same result as on my phone. It opens the php file as text. (or so it seems)
Hi Makube,

Maybe I didn't explain it correctly, but I've transferred the three files to my webspace.

I really don't know if it then functions as a server. (Or is that what the php file has to do? Act as a server.) Perhaps that is the problem.


grz Thijs

Anonymous said...

Howdy,
can you tell me which S40's implement the progressive download you are mentioning ?

Makube said...

Hi,

all the newest S40 devices should support progressive download, for instance the Nokia 3120 classic.
It's a S40 5th Ed FP1 device. More devices can be found here: http://www.forum.nokia.com/devices/matrix_s40_5ed_3.html

Best
Makube

TiGeR said...

How do you specifically use this progressive download funcitonality of the latest S40's ?
Is that some kind of attribute in the jad file, or is it by using a http stream instead of an rtsp ?

Makube said...

Hi TiGeR,

I use it this way:
------------------------------
String url =serverurl+"?play="+streamurl+"&clientid=123234324";

HttpConnection con= (HttpConnection)Connector.open(url);
InputStream is = con.openInputStream();
player = Manager.createPlayer(is, "audio/mpeg");

player.realize();
player.prefetch();
player.start();
--------------------------
The serverurl must include the port number of your server.

You can also try the solution suggested at: http://wiki.forum.nokia.com/index.php/How_to_play_mp3_from_server_in_Java_ME

Best
Makube

TiGeR said...

So you just use that code ?
No attribute in the JAD ?
Cause it just doesn't seem to work for me... Does the application has to be signed ?

Makube said...

Hi TiGeR,

exactly, I just use this code for the S40 Nokia devices. What device do you have? Sure it's a new S40 device? This solution will not work
on S60 devices btw. I have developed a special solution for S60 devices, but it is not yet published.

But you can try to add the progressive download property in the Jad/Jar. You can also PM me in order to solve the problem. You find my mail in my blogger profile.

Thanks
Makube

Nicolas said...

Firstly ... thank you very much!
I own a Samsung A736 (not very known)... anyway, I could install de JAD/JAR, for those trying to install, best option is to point your phone browser to the .jad file -I suppose you can host files- and install, make sure your mime-type from .jad and .jar are ok!!! .

I got the station list working, but when I try to play I get a "failed to connectresponse empty" with several stations I tried.

The problem resides in my php server, the logs says something like:
fsockopen() [function.fsockopen]: unable to connect to 85.25.148.195:8017 (Connection refused) in ...

any Idea? firewall?
regards and thank you!

Makube said...

Hi Nicolas,

it could also mean that the url is really not available. I checked the IP you provided and it didn't work.
You can create own mr.xml files (the station list) to have an uptodate list. Surely you have done this, but also make sure to have the php.ini in the same server directory as the meradio.php5 and that the property
allow_url_fopen = on is set.

Best
Makube

Nicolas said...

Makube, thanks for the fast reply. I checked some URLs and finally made it work (server side) .. I uncommented the code to write the file locally as .mp3 (just to be sure the stream was ok) and then I could hear it loud and clear ( winamp)... so far so good, the server part is OK.

About the Java app... As I told you, I own a SGH-a736, the app installed ok, but I still get
"java.io.IOException: failed to connectresponse empty failed to connectresponse empty"
seems no response is downloading to the phone and connection is aborted.

My guess was progressive download was the error, so I tried a 10 segs download just to test it (again I wrote the file to disk and checked I could hear music with the 10segs .mp3 - OK). and now I get a "java.io.IOException: bad url bad url" error.
Dunno what might be... I have yet to debug the java App. Any ideas are welcome.

Regards,
nicolas

Makube said...

Hi Nicolas,

unfortunately, I dont own a Samsung or Motorola device. I will not be able to able to assist you directly.
But lets be honest, the Java Me implementation of the above mentioned vendors are really full of bugs and often do not comply with the standards. Nokia and SonyEricsson have much better implementations. It already starts with the OTA-only installation procedures, which is bad for developers. I dont know, if your device even supports progressive download.
However, if you figure it out how you can get the streaming to work, I would be very grateful if you would share your knowledge here.

Best
Makube

Anonymous said...

Hi... I tried to install the client into a CECT i9 V802 (first with SonyEricsson version and after with Nokia version) but I sometimes get the errors below:

java.io.IOException: error 11 during HTTP over WSP (is always shown)

less shown:

java.lang.NullPointerException: 0 0

javax.microedition.media.MediaException: error opening Audio device

javax.microedition.media.MediaException: Memory is run out!

I get this error after a "Play".

The device has two memory areas (one internal with few bytes and a MicroSD 2 GB) and is MIDP 2.0 .

Radio lists appear correctly and I followed the procedure for the server, php.ini included.

I'm not an expert but I think could be a phone limitation, or could be a server problem? And the first problem what does it mean? TIA

Anonymous said...

I forgot to write that I never heard any radio! :)

Makube said...

Hi,

ther errors you describe suggest that your device does not support progressive download. The phone tries to download the mp3 from the server, but as an end can never be reached (it's a stream) the music does not start and the memory full error occurs. In the next Meradio version I will integrate a double buffering solution that even works on devices with no progressive download support e.g. S60 devices.

Best
Makube

host2india said...

It works with me very fine,thanks a lot joshua E66 NOKIA.

Makube said...

That is great. Thanks for reporting back!

Makube

amdma2003 said...

Hello,
I installed this on a Motorola ZN5 using the Nokia jar files and it works great!
I had some trouble getting the php file to execute correctly because it would return a Fatal Error: mb_convert_encoding undefined function.
Appending dl('php_mbstring.dll'); to the beginning of the php file made it work fine.
Other than the php errors, this works very well, much better than all the other mobile radios I have used. It doesn't skip, simple interface, and it also runs when you idle the application.

Makube said...

Thanks amdma2003 for your valuable feedback and your report how it worked on a Non-Nokia device.

:-)

Best
Makube

Marek said...

What is the folder src ?

MeRadio.java and RMSCache.java install at a phone ? Would a detailed guide

Makube said...

Hi Marek,

the src folder contains the sourcecode in case you want to enhance the program yourself. To install MeRadio you have to put the correct Jar file on your phone, depending on your phone model.

Best
Makube

Marek said...

How do I set the application make it work? In Settings, I will address stream and nothing genres and give nothing. How to configure?

Marek said...

I have SE and application write this
java.io.IOException:bad url bad url

Anonymous said...

Sorry, i don't have a account. But where can i download the server files? I see only meradio.zip. Maybe you can give extra info where to them on the server and how the configuration works. Want to test this with my webspace and SE C905. Many thanks in advance.

rudiev

Ankit said...

Sir
i am totally confused. I didnt understand this webspace and php and what i downloaded from second link only is20kb ext file which is not supporting(nokia supernova 7210 5th editions40)
what i have to do plz tell in detail if u plz u can mail me at ankit5311@gmail.com i will be thank full to u
do i have sth more to download if plz provide link or attach it in a mail
i will be looking for your mail

Makube said...

Hi Ankit and the other anonymous user,

I'm very sorry. The version 0.2a you downloaded did not include the server files. Thank you for bringing this to my attention. The correct files are uploaded now.

When you open the downloaded zip archive you see the directories MIDlet and Server. The first dir contains the Java ME application for Nokia and Sony phones and the source code. Install the Jar files to your phone.

The Server dir contains the php and XML needed to relay the stream as described in the post. You will have to install the files in one directory of your webspace.


Good luck with it.

Makube

kaio said...

good work ! can you give us a tutorial to how put these files in a webspace it's a bitconfusing and I realy want to give this a try ! thanks in advance

Anonymous said...

wowwwwww

Dean said...

greetings to all.
I would first like to thank the writers of this blog by sharing information, a few years ago I read a book called guanacaste costa rica in this book deal with questions like this one.

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

Sayem said...

Hello,

Awesome! But i get this following error when when I try to play any channel in the mobile:

Exception

javax.microedition.media.MediaException: start start

Can you tell where the problem is?

Thank you

william said...

whoa!!!, you had a passion in blogging, thumbs up for your work of love.. Hehe very inspiring ideas,


anyway I'm william
mind if I put a link back to you?


(clickable) ------> alligators shoes

maimmj said...

hi Makube.
I just found about ths app lately. i've tried it on my SE w705 and it didn't work. maybe i put the wrong address, i'm not sure.
about ths address: [http://yourhostname/meradio.php5?play=http://sc3.radioseven.se:8500/&clientid=123234324]
should I replace anything or leave it as it were?

pavan kumar said...

Hiiiii
Excellent, but The given download links are not working,can you give me the source code,
Thanks in advance.........

pavan kumar said...

Hiiii,
i am trying for shoutcast internet Radio streaming on j2me MIDP for last one week,i am facing problems regarding this,i tried to open a connection to this URL"http://38.101.195.5:9156" with HttpConnection,i am not able to get,
Can u please help me out ....
thanks
pavan
pavankumarragi@gmail.com

joyahm said...

new link please.....

download link has dead....

Cheryl Long said...

Having lived in Boca Raton for several years, listening to the 103.1 WIRK has become a daily ritual for me. I start my day with a cup of coffee and a side of the 103.1 ‘Morning Show’ with DJ Tiny. For the rest of the day I enjoy great tracks by some of my favorite artists. The station’s great selections of Country music adds so much needed groove to my day! The 103.1 is a stay at home mom’s best source for great
entertainment. Tune in today or stream online at www.wirk.com!

Sean Prince said...

Being an ardent fan of Pop and Adult Contemporary music, Sunny 107.9 is always my first choice for non-stop entertainment. Whether in my car or at home I’m always tuned in and kept entertained by the stations great music. Stream online at www.sunny1079.com or tune in live.

Philippine Women for Marriage said...

Thanks for taking the time out to share this with the readers. I was greatly interested with what you have shared and posted with us.