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
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified
Accepted Solution

Streaming Large Audio

[ Edited ]

I am getting very frustrated.

 

I've been trying to stream audio for the last few days in one of my apps. I have basically exhausted all resoruces on here trying to find a working example, and I'm at the point of where I want to smash my computer.

 

I tried a simple way of streaming using a Media Manager, which actually worked the best for small files. The problem is as soon as the mp3 file is over XXX amount of megs (some large size, lets say 300mbs), I get a 413 error on the device when not streaming by WiFi.

 

_player = Manager.createPlayer(_source);
_player.start();

 

So obviously I can't use this method of streaming the media.

 

I then checked out "BufferedPlayback" demo - which is a complete nightmare in itself.

 

Essentially, it seems that anything in OS5 causes the ContentConnection to return null. This is completely useless since OS5+ is what I'm targeting.

 

From the JDK:

 

	        // Open the connection to the remote file
	        _contentConnection = (ContentConnection) Connector.open(getLocator() + Networking.getConnectionString());

 

So I was then recommended to visit the "end all be all" streaming media on the BB which is here:

 

http://supportforums.blackberry.com/t5/Java-Development/Streaming-media-Start-to-finish/ta-p/488255

 

Now, this RIM example uses a Circular Byte Buffer - which they don't supply a WORKING piece of code to.

 

The example that is linked has a resize() function, but that function does not exists.

 

						buffer.resize(buffer.getSize() + (buffer.getSize() * percent / 100));

 

So you can see where I am getting extremely fed up with these non-working examples, or incomplete ones.

 

Can anyone link me, or tell me, how to stream a large mp3 file on BB without it blowing up?

Thanks!

Please use plain text.
Developer
haagmm
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: Streaming Large Audio

I would say that they suggestion for large files was to use WAP or WAP2.  The issues with WAP are that you will still need apn etc, but for WAP2 you should be able to use it for all networks without APN information.  check out the WAP2 options in here

 

http://www.versatilemonkey.com/HttpConnectionFactory.java

Please use plain text.
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

BlackBerry 413 Error

In case anyone was wondering, I "solved" the 413 error (hopefully). There were actually two methods that I used to solve the issue.

 

1) Using a direct TCP connection (which required a user to have an APN setting)

 

2) Using WAP2 conncetion (which ultimately solved the issue).

 

So basically the problem was that the carrier was sending back "413 File To Large" to the BlackBerry. Using Murel's suggestion, I used WAP2 as the transport layer and everything was AOK.

 

I used this to force a WAP2 connection (I try wifi, wap2, bis, t

 

cp, any)..

 

http://www.versatilemonkey.com/HttpConnectionFactory.java

 

I try all connections, and one I find one that works I use it. I started by using an InputStream, but according to the JavaDocs you can't "seek" via an InputStream, so instead I used the HttpConnectionFactory to determine the connection string, then used it to create a MediaPlayer, which then I could "seek" with using setMediaTime(123456);

 

A better way would be probably modifying HttpConnectionFactory just to return the connection string, but this will work for my purposes.

 

HttpConnectionFactory factory = new HttpConnectionFactory("http://url.com/file.mp3"),
						HttpConnectionFactory.TRANSPORT_WIFI | HttpConnectionFactory.TRANSPORT_WAP2 | HttpConnectionFactory.TRANSPORT_BIS
								| HttpConnectionFactory.TRANSPORT_DIRECT_TCP | HttpConnectionFactory.TRANSPORTS_ANY);

				while (true)
				{
					try
					{
						HttpConnection connection = factory.getNextConnection();

						try
						{
							connection.setRequestMethod("GET");
							connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");

							connection.openInputStream();

							//do something with the input stream
							if (connection.getResponseCode() == 200)
							{
								Global._player = Manager.createPlayer(connection.getURL());
								Global._player.start();
								break;
							}
						}
						catch (IOException ex)
						{
							//Log the error or store it for displaying to the end user if no transports succeed
						}
						finally
						{
							connection.close();
						}
					}
					catch (NoMoreTransportsException e)
					{
						//There are no more transports to attempt
						General.popup("Unable to perform request"); //Note you should never attempt network activity on the event thread
						break;
					}
				}
Please use plain text.
Developer
footose
Posts: 300
Registered: ‎03-12-2009
My Device: Not Specified

Re: Streaming Large Audio

Ha! I was just typing that up!
Please use plain text.