views:

479

answers:

0

Hi

I want to play video in my app for which I will get urls from server. I got lot of codes but nothing was working. If I add the video as file (*.mp4) in src folder (how we used to add images in the source folder), then I could play the video by using the following code.

  Class playerDemoClass = Class.forName("com.rim.samples.multimediademo.MultimediaDemo");    
  InputStream inputStream = playerDemoClass.getResourceAsStream("/samplemp4.mp4");    
  _player = javax.microedition.media.Manager.createPlayer(inputStream,"video/mp4");                               
  _player.realize();   

 //Add listener to catch Player events
 _player.addPlayerListener(this);    

 //Get the Player VideoControl
 _videoControl = (VideoControl) _player.getControl("VideoControl");

 //Initialize video display mode
 _videoField = (Field) _videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,"net.rim.device.api.ui.Field");

 //Set the video display size to 200 x 200 
 _videoControl.setDisplaySize(360, 280);

//Create a manager for the video field
_videoManager = new VideoManager(); _videoManager.add(_videoField); add(_videoManager);

//Set video control to visible 
_videoControl.setVisible(true);

//Start the Player 
_player.start();

But using this code also I couldn't play .flv, .3gp and .m4v files (even after adding those files in the src folder)

And I used following set of codes to play the video via http streaming.

1: Using HttpConnection

InputStream inputStream = null;
try {
  ConnectionFactory connFact = new ConnectionFactory();
  ConnectionDescriptor connDesc; connDesc = connFact.getConnection("http://amazon.vrvm.com/6433-360809725.3gp");
  HttpConnection httpConn = null;
  if (connDesc != null) {
    httpConn = (HttpConnection)connDesc.getConnection();
    inputStream = httpConn.openInputStream();
    int responsecode = httpConn.getResponseCode();
  }
} catch (Exception e) {
  Dialog.alert("Exception in playing audio:"+e.toString());
}

_player = Manager.createPlayer(inputStream,"video/3gpp");

_player.realize();

//Add listener to catch Player events 
_player.addPlayerListener(this);

//Get the Player VideoControl 
_videoControl = (VideoControl) _player.getControl("VideoControl");

//Initialize video display mode 
_videoField = (Field) _videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,"net.rim.device.api.ui.Field");

//Set the video display size to 360x 280
_videoControl.setDisplaySize(360, 280);    

//Create a manager for the video field 
_videoManager = new VideoManager();
_videoManager.add(_videoField); add(_videoManager);

//Set video control to visible
_videoControl.setVisible(true);

//Start the Player 
_player.start();

1: Using ByteArrayInputStreamDataSource

Parsed the url and converted as byte array

 ByteArrayInputStream stream = new ByteArrayInputStream(data);
 ByteArrayInputStreamDataSource source = new ByteArrayInputStreamDataSource(stream, "video/3gpp");

then passed this ByteArrayInputStreamDataSource object to Manager.createPlayer().

To get the inputstream, I have used openDataInputStream() and openInputStream().

but nothing works. I couldn't stream rtsp urls too.

Sometimes I got blackscreen with audio.

FYI - I am using Blackberry JDE componenet 5.0.0.7 (Beta) and the simulators 8900, 9000 and 9500 to test my app.

Could anyone help me to solve this issue. Thanks in advance.