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
Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Internet Radio on Blackberry java

[ Edited ]

i developed an Rss Application,which displays list of Radio channels from Rss File.initially when channels are displayed immediately i am able to play my first channel by default for that i have written a method playRadio(String url) .

but my requirement is when the user clicks on second,third channels etc.....i need to play the respective channels for that i have written ListField Navigation Method,in that method i invoked my playRadio(String url),but my problem is when the list initially loads ,i am able to play the default channel(First),but when i click on any channel i am able to invoke my playChannel(String url)but i am not able to play the respective channel,still i am able to play the default channel,can any one help me?

 

Here my code for playing channels:

 

private void playChannel(String url) {
            System.out.println("URL"+url);

            _urlField = new BasicEditField("URL:",url);
            add(_urlField);

               try {
                  if (_player == null)
                  {
                      // Create a stream using the remote file.
                      _source = new ShoutcastStream(_urlField.getText());

                      UiApplication.getUiApplication().invokeLater(new Runnable()
                      {
                          public void run()
                          {
                              // Update the player status
                              _playStatusField.setText("Started");
                          }
                      });

                      // Create and run the player's thread
                      _playerThread = new PlayerThread();
                      if (_playerThread != null) {
                        _playerThread.start();
                      } else {
                        System.out.println ("PlayerThread is null.");
                      }
                  }
                  // The player already exists, simply resume it
                  else
                  {
                      _player.start();
                  }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (MediaException e) {
                errorDialog(e.toString());

e.printStackTrace();            }



    }

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Internet Radio on Blackberry java

Looking at this code, if the _player is instantiated, this method is not going to point it at the new URL - so this looks like a simple logic error, Before we look hard at this code, why don't you debug it, demonstrate to your own satisfaction that the processing is doing what you expect it to do when the URL changes.  Look at the JavaDoc for Player for an idea of what it should do. 

Regular Contributor
Posts: 63
Registered: ‎08-30-2012
My Device: 9900
My Carrier: Various

Re: Internet Radio on Blackberry java

[ Edited ]

hii here is my PlayerThread class:

 

private class PlayerThread extends Thread {
        /**
         * Create and start the player
         *
         * @see java.lang.Runnable#run()
         */
        public void run() {
            try {
                _player = Manager.createPlayer(_source);
                if (_player != null) {
                    _player.start();
                } else
                    System.out.println("Failed to start player");
            } catch (final Exception e) {
                // Acquire the UI lock
                UiApplication.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        _playStatusField.setText("Stopped");
                        try {
                            if (_player != null)
                                _player.stop();
                            destroy();
                        } catch (Exception eNew) {
                            System.out.println("Error: " + eNew.getMessage());
                        }
                        // _player = null;
                        System.out.println("Error: " + e.getMessage());
                    }
                });
            }
        }
    }
can you check this code?

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Internet Radio on Blackberry java

I'm not trying to be rude here, but I don't think it is our job to check your code is it?  It is your code, you have been paid to write it.  We have no idea how this code fits in your application nor what you have designed it to do.  What are we supposed to check?

 

But if you pin-point the bit of code that is causing your grief then we can help with that.   So please do as I indicated in my previous post and debug this code.  What is happening on navigationClick?  Where does it get to in your code.  What bit of your code do you expect to change the station? 

 

I would expect you to have a planned flow of actions in your code and then you can check that your code is actually following that plan.  This plan would be driven by the documentation, so that it matches what should happen to a Player. 

 

If your code, according to the documentation and what it is actually doing, should be working correctly, then please tell us the sequence of events that has happened and point out the bit of your code that is not doing what you expect.  Tell us what it does do and what you expected it to do.