Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Munon
Posts: 3
Registered: ‎02-26-2013
My Device: Blackberry Torch 6
My Carrier: Movistar

Radio app in Blackberry 5

I'm building a Radio app player for BB 5, but I don't find the way to play a .pls file with the microedition player. I've also other resources as .aac or .m3u, but when I try to play them, I always find a RuntimeException. I think that it could be something about buffering data or something. I paste my code below:

 

 

 

System.out.println("CREA el player");
//                            InputStream stream = Connector.openInputStream(urlPlay);
                            StreamConnection streamConnection = (StreamConnection) Connector.open(urlPlay, Connector.READ);
                            InputStream  readAhead = streamConnection.openDataInputStream();
                            byte[] audioData = new byte[5000];
                            readAhead.read(audioData,0,audioData.length);
                            ByteArrayInputStream in2 = new ByteArrayInputStream(audioData);
                            player = javax.microedition.media.Manager
                                    .createPlayer(in2, "audio/aac");
                            System.out.println("REALIZE");
//                            player.realize();
                            System.out.println("PREFETCH");
//                            player.prefetch();
                            System.out.println("START");
                            player.start();
                            System.out.println("Todo ok!");
                        }catch(RuntimeException r){
                            Dialog.alert("error");                        
                        } catch (IOException e) {
                            Dialog.alert("No se puede reproducir IOEXception");
                            e.printStackTrace();
                        } catch (MediaException e) {
                            Dialog.alert("No se puede reproducir MediaException");
                            e.printStackTrace();
                        }

Please use plain text.
Developer
simon_hain
Posts: 15,940
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Radio app in Blackberry 5

welcome to the support forums.

a few things on the side: networking should not be done on the event thread. see http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865
if you use a separate thread dialog.alert etc must be wrapped into invokelater.

pls or m3u files are just text files with the uri to the file that should be played, you have to parse these files yourself and call the correct uri.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Munon
Posts: 3
Registered: ‎02-26-2013
My Device: Blackberry Torch 6
My Carrier: Movistar

Re: Radio app in Blackberry 5

Oh! Sorry I don't know that this is not the proper site to do that.

In my .pls I have so many URLs, how I know which is the correct?
Please use plain text.
Developer
simon_hain
Posts: 15,940
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Radio app in Blackberry 5

good question.
you can try them maybe. difficult to say without knowing anything about it :smileyhappy:
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
Munon
Posts: 3
Registered: ‎02-26-2013
My Device: Blackberry Torch 6
My Carrier: Movistar

Re: Radio app in Blackberry 5

Please use plain text.