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
New Contributor
alsidorov
Posts: 6
Registered: ‎11-08-2011
My Device: Torch 9800
My Carrier: None
Accepted Solution

Unable to play video on BB OS 7

Hello Devs!

I need to play video avi file("rolik.avi") that is located in app resurces folder on my apps screen.

I'm using the following code for my screen

public class VideoScreen extends MainScreen implements PlayerListener {

	private Manager layoutManager;
	private Player player = null;
	private Field videoField;

	 public VideoScreen(){

              try {
                  ByteArrayInputStream stream = (ByteArrayInputStream)this.getClass().getResourceAsStream("/rolik.avi");
		  ByteArrayInputStreamDataSource source = new ByteArrayInputStreamDataSource(stream, "video/x-msvideo");
		  player = javax.microedition.media.Manager.createPlayer(source);
		  player.realize();
		 player.prefetch();
              }catch (Exception e){
              }
	      VideoControl videoControl = (VideoControl) player.getControl("VideoControl");

	      videoField = (Field)videoControl.initDisplayMode( VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );
	      videoControl.setVisible(true);
	      try {
		videoControl.setDisplaySize(440,330);
	      } catch (Exception e) {
		 e.printStackTrace();
	      }
	      videoControl.setDisplayLocation(10,10);
         
	 layoutManager = new Manager(Manager.USE_ALL_HEIGHT | Manager.USE_ALL_WIDTH){
            protected void sublayout(int width, int height) {
		setPositionChild(videoField, 10,10);
		layoutChild(videoField, 440, 330);
                 setExtent(width, height);
	    }
				
	    protected void paint(Graphics g){
		super.paint(g);

	    }
         };
	 layoutManager.add(videoField);
	 add(layoutManager);
	 player.addPlayerListener(this);
         try {			
	      player.start();
	 } catch (Exception e){
	    e.printStackTrace();			
	 }
      }
      public void playerUpdate(Player player, String event, Object eventData) {
	  System.out.println("PLAYER EVENT:::::"+event);
	  if (event.equals(PlayerListener.END_OF_MEDIA)){
	     close();
	  }
      }
}

 When launching this code in debug mode on 9930 simulator I see the following output in console:

PLAYER EVENT:::::durationUpdated
PLAYER EVENT:::::com.rim.seekableUpdatePLAYER EVENT:::::com.rim.playableStreams
PLAYER EVENT:::::com.rim.mediaLoaded
PLAYER EVENT:::::started
PLAYER EVENT:::::com.rim.timeUpdate
PLAYER EVENT:::::bufferingStarted
.........................
[ReadThread run]: net.rim.device.internal.streamingnatives.StreamingException: Unexpected erorr
.........................
PLAYER EVENT:::::error

So, I think, that video is not played because of Streaming exception. But what can cause this exception to appear?
The same video and code perfectly works on OS 5 and 6 devices and simulators.
Is there any other ways to play the video that is the part of application?
Please help!

Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Unable to play video on BB OS 7

I Tested your code on my 9930 simulator using OS7, it works just fine so I expect the issue is with your avi file.

 

 

Please use plain text.
New Contributor
alsidorov
Posts: 6
Registered: ‎11-08-2011
My Device: Torch 9800
My Carrier: None

Re: Unable to play video on BB OS 7

I've tried to use different video types - wmv, avi, mp4 and results are all the same

[ReadThread run]: net.rim.device.internal.streamingnatives.StreamingException: Unexpected erorr

 crispyoz, what was the size of the video file that you used?

Please use plain text.
Developer
crispyoz
Posts: 223
Registered: ‎10-01-2011
My Device: Bold 9900

Re: Unable to play video on BB OS 7

[ Edited ]

I tested a few but for example 1.8MB avi 240x180 @ 420kps.

 

Are you using 7.0 or 7.1?

Please use plain text.
New Contributor
alsidorov
Posts: 6
Registered: ‎11-08-2011
My Device: Torch 9800
My Carrier: None

Re: Unable to play video on BB OS 7

I used 7.0 simulator.

But now I've tried to use 7.1 simulator and see other issue - 

(VideoControl) player.getControl("VideoControl") returns null 

Please use plain text.
New Contributor
alsidorov
Posts: 6
Registered: ‎11-08-2011
My Device: Torch 9800
My Carrier: None

Re: Unable to play video on BB OS 7

Finally found the issue.
I navigated to my VideoScreen from the screen where another active instance of the Player(audio player) were in the process of stopping. I've added a small delay to wait untill active instance of player is stopped before pushing my VideoScreen.

Please use plain text.