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
Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

This is the function I use to play and pause, and move to the next track.When the user clicks next, I call the function destroy(), and then recreate the player when the user clicks start again.

 

The exception I get is from the ConnectionThread, the thread doesn't stop. It gives me an exception and contines to download the song, which is reflected from the read() method.

 

thanks so much for your replies

 

 

 

 

public void fieldChanged(Field field, int context)
	{
		try
		{
			//If the START button was pressed, begin playback.
			if (field == _startPlayingButton)
			{
				//The player does not exist, we must initialize it.
				if (_player == null)
				{ 
					setPauseButton();
					//Create a stream using the remote file.
					if(_source == null){
						_source = new LimitedRateStreamingSource(getSongURI()+MainUI.connectionParameters);
					}else{
						if (_source != null)
						{
							_source.stop();
							_source.disconnect();
							_source = null;	
							_source = new LimitedRateStreamingSource(getSongURI()+MainUI.connectionParameters);
						}					
					}					
					_source.setContentType(_mimeField);
					_source.setStartBuffer(_startBufferField);
					_source.setReadLimit(_readLimitField);
					_source.setResumeBytes(_resumeBytesField);
					_source.setPauseBytes(_pauseBytesField);
					_source.setLoadStatus(_loadStatusField);
					_source.setPlayStatus(_playStatusField);
					//_source.set_progressStatusField(_progressStatusField);
					_source.setProgressBar1(bufferDownloadBar);
					_source.setTimeLine(timeLine);								
					//Create and run the player's thread.
					_playerThread = new PlayerThread();
					_playerThread.start();
					
				}
				//The player already exists, simply resume it.
				else
				{
										try {								
								_player.stop();
								setStartButton();
							} catch (MediaException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}	
						}						
					}else{						
						_player.start();
						setPauseButton();
					}
				}
				
			}else if(field == _movePrevPlayingButton){

									JSONObject temp = getPreviousTrack();
					if (temp != null) {
						setDefaultButton();
						setCurrTrack(temp);
						destroy();
						initialiseJSONStream(temp);
						_playStatusField.setText("Stopped");		
					 
				}
			}else if(field == _moveNextPlayingButton){
							setDefaultButton();					
					JSONObject temp = getNextTrack();
					if (temp != null) {					
						setCurrTrack(temp);
						destroy();
						initialiseJSONStream(temp);					
						_playStatusField.setText("Stopped");
					}  
				}
					}
		catch (Exception e)
		{
			System.err.println(e.getMessage());
		}
	}

 

 

 

 

Developer
Posts: 70
Registered: ‎11-24-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

In my case I keep the downloader thread in a while loop

 

public void run()
{
    stopThread = false;
    ...
    available = stream_http.available();
    while(available > 0)
    {
        if(stopThread)
        {
            return;
        }
        ....

        syncrnizedblock
        {
            ...
            read()
        }

        if(stopThread)
        {
            return;
        }
        ...
        available = stream_http.available();
    }
}

 

and I set  stopThread from inside the disconnect and the stop methods of source (StreamingMediaSource) class.

 

So that ways the thread can exit normally.

 

 

 

 

 

Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

Is there any chance you could post your code, the bufferedplayback and the limitedstreamingsource?

Developer
Posts: 70
Registered: ‎11-24-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

I have already posted the code for bufferedplayback and the limitedstreamingsource at the start of the thread.

I cant really post the code for the main application, m sorry about that. But the psuedos that I have mentioned in the messages above are more or less similar to my code.

Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

Lovish,

 

Did you by any chance have any issues where the download stream wouldn't stop downloading? When I try to stop the thread that's downloading I get an exception.

Developer
Posts: 70
Registered: ‎11-24-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

HI Hades, No I have not faced such an issue till date. -Lovish
Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

[ Edited ]

I found the problem, it was because the thread which was reading the stream didn't stop in time, and then trying to close the stream resulted in an exception. I fixed this by adding a sleep statement. Also this was more apparent when running on EDGE, on WiFi it wasn't really an issue.

New Developer
Posts: 16
Registered: ‎08-04-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

Hey guys, Posting the code ? I have developed a player myself and its kind a failing. Was wondering if you can post your code for me to check out...
Developer
Posts: 178
Registered: ‎08-26-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

Check pages 1 and 2. There is a version of the bufferedmedia example without saving it on the device. It's by Lovish, if you still have issues let us know.

Developer
Posts: 70
Registered: ‎11-24-2009
My Device: Not Specified

Re: Graphical UI for Audio Streaming

Thats great