Playing an InputStream video in Blackberry JDE-Collection of common programming errors

I think I’m using InputStream incorrectly with a Blackberry 9000 simulator:

I found some sample code,

that lets you play video from within a Blackberry App. The code claims it can handle HTTP, but it’s taken some fandangling to get it to actually approach doing so:

Specifically, I’m doing:

 StreamConnection s = null;
            s = (StreamConnection)"");
            HttpConnection c = (HttpConnection)s;                        
           InputStream i = c.openInputStream();
            System.out.println("~~~~~I have a connection?~~~~~~" + c);
            System.out.println("~~~~~I have a URL?~~~~" + c.getURL());
            System.out.println("~~~~~I have a type?~~~~" + c.getType());
            System.out.println("~~~~~I have a status?~~~~~~" + c.getResponseCode());

            System.out.println("~~~~~I have a stream?~~~~~~" + i);
             player = Manager.createPlayer(i, c.getType());

I’ve found that this is the only way I can get an InputStream from an HTTPConnection without causing a: “JUM Error 104: Uncaught NullPointer Exception”. (That is, the casting as a StreamConnection, and THEN as an HttpConnection stops it from crashing).

However, I’m still not streaming video. Before, a stream wasn’t able to be created (it would crash with the null pointer exception). Now, a stream is being made, the debugger claims it’s begining to stream video from it…and nothing happens. No video plays.

The app doesn’t freeze, or crash or anything. I can ‘pause’ and ‘play’ freely, and get appropriate debug messages for both. But no video shows up.

If I’m playing a video stored locally on the blackberry, everything is fine (it actually plays the video), so I know the Player itself is working fine, I”m just wondering if maybe I have something wrong with my stream?

The API says the player can take in an InputStream. Is there a specific kind it needs? How can I query my inputstream to know if it’s valid? It existing is further than I’ve gotten before.


Edit: I’m on a Blackberry Bold simulator (9000). I’ve heard that some versions of phones do NOT stream video via HTTP, however, the Bold does. I have yet to see examples of this though. When I go to the internet and point at a blackberry playable video, it attempts to stream, and then asks me to physically download the file (and then plays fine once I download).

Edit: Also, I have a physical blackberry Bold, as well, but it can’t stream either (I’ve gone to, only to get a server/content not found error). Is there something special I need to do to stream RTSP content?

  1. So, after a very long time I have determined that the Blackberry Bold 9000 does NOT do http streaming. I ended up having to (or rather a coworker of mine having to) write custom methods for progressive download to simulate it. Oh, well.

  2. You should be able to stream actually. Firstly, you must make sure you are appending the correct connection parameters to your URL (ie. “;interface=wifi” for a wifi connection). Secondly, you have to make sure the file you are streaming is not too large. If it is too large, you will get an HTTP error stating “file too large”. In order to fix this, you need to buffer things (Check out the DataSource APIs). You should limit what you request to about 1-2MB. After you have pulled that “chunk” you need to keep requesting sequential chunks (with separate http connections) to continue to fill you buffer. I hope this helps

Originally posted 2013-11-19 13:17:41.