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: 101
Registered: ‎02-10-2009
My Device: Q10, Z10
My Carrier: T-Mobile
Accepted Solution

AdvancedVideoControl not working as it should?

I have been playing around with the new AdvancedVideoControl in OS 7.0, trying to add a video to a screen while having fields overlaid on top.

 

Unfortunately I didn't have much luck. The video plays, but it hides all the fields in the screen. Only when the video finishes the fields become visible.

 

Maybe the way I am using it is wrong? Anyone had any luck with it?

 

  Field videoField;
  try {
    Player p = Manager.createPlayer("file:///store/home/user/videos/sample.mp4");
    p.realize();
    AdvancedVideoControl vc;
    if ((vc = (AdvancedVideoControl) p.getControl("net.rim.device.api.media.control.AdvancedVideoControl")) != null) {
      videoField = (Field) vc.initDisplayMode(AdvancedVideoControl.USE_GUI_ADVANCED, "net.rim.device.api.ui.Field");
      vc.setVisible(true);

      // custom manager takes care of placing labelField on top of videoField
      customManager.add( videoField );   // video in background
      customManager.add( labelField );   // this field should show on top
    } else {
      System.out.println("Failed getting AdvancedVideoControl");
    }
    p.start();
  } catch (Exception e) {
    System.out.println("Failed loading video " + e.getMessage() + " " + e.getClass());
  }

 

 

Retired
Retired
Posts: 150
Registered: ‎10-19-2010
My Device: Not Specified
My Carrier: Rogers

Re: AdvancedVideoControl not working as it should?

[ Edited ]

Hi pfluger!

 

The BlackBerry 7.0 Multimedia guide will contain sample code that hows you how to do this.  I say will because the current beta version you have access to now doesn't have it yet...

 

This deserves a KnowledgeBase article of it's own, but I'm still working on that.  In the meantime here is some information you should know:

 

  • Put your UI fields that will be displayed over top of the video into a net.rim.device.api.ui.container.ComponentCanvas.  The ComponentCanvas extends an AbsoluteFieldManager.  As the JavaDoc explains: "Unlike AbsoluteFieldManager, this manager is drawn on the screen using the compositing engine".  The compositing engine is what will 'blend' the video and other fields on the screen into one seemless screen.
  • The video field you obtain in your code below must have a lower Z-order than the other components on the screen.  To do this, add it to the screen's manager before you add your ComponentCanvas that will be displayed over top.
  • Finally, there appears to be an issue (that's why it's beta Smiley Wink) such that you may have to call ComponentCanvas.invalidate() to force a repaint of the UI fields over the video.  I have found I need to do this when using a viewfinder obtained from a video recording player, it may or may not apply to playback video fields I am not sure.

 

One final note that doesn't apply to your situation but is pretty relevant, if you create a Player for video recording or still image capture (using a locator like "capture://video" for example) then AdvancedVideoControl.USE_GUI_ADVANCED is not available

 

Don't worry though!  A field obtained by using VideoControl.USE_GUI_PRIMITIVE will behave in the same way as AdvancedVideoControl.USE_GUI_ADVANCED for this case.

Developer
Posts: 101
Registered: ‎02-10-2009
My Device: Q10, Z10
My Carrier: T-Mobile

Re: AdvancedVideoControl not working as it should?

Putting all fields in a ComponentCanvas did it. Working beautifully now. Thanks a lot!

Highlighted
New Contributor
Posts: 3
Registered: ‎02-22-2011
My Device: 8830,8520,900,9700,9800
My Carrier: Mobile application developer

Re: AdvancedVideoControl not working as it should?

Hi,

 

I tried the steps you suggested but in vain.

I am not able to put a field on top of a camera view. Even invalidating the component canvas din't work.

Could you please through some extra light on this issue, perhaps, with some code? especially since you have solved the issue. It would be very helpful for me and may be for a lot more folks stuck in this issue.

Retired
Retired
Posts: 150
Registered: ‎10-19-2010
My Device: Not Specified
My Carrier: Rogers

Re: AdvancedVideoControl not working as it should?

[ Edited ]

The 7.0 release will contain sample code but for now here's some code you can adapt that I simplified from my application that should work.  Excuse some of the formating, I did it so it would look nicer in this forum:

 

public class MyScreen extends MainScreen {

// Holds all fields on my screen
private ComponentCanvas screenManager;

// Bitmap container overlaps video viewfinder
private ComponentCanvas bitmapWindow;

int videoWidth;
int videoHeight;

public MyScreen() {
videoWidth = Display.getWidth();
videoHeight = Display.getHeight();

screenManager = new ComponentCanvas(videoWidth, videoHeight);

// Bitmap is 50% size of viewfinder:
bitmapWindow = new ComponentCanvas(videoWidth / 2, videoHeight / 2);
}

/** {@inheritDoc} */
public void doLayout() {
super.doLayout();

deleteAll();
add(screenManager);
}


/** Setup a viewfinder with overlapping bitmap */
public void doSomething() throws IOException, MediaException {
// Lets just grab some top-left corner of screen as a bitmap to use:
final Bitmap bitmap = new Bitmap(Bitmap.ROWWISE_32BIT_ARGB8888,
videoWidth/2, videoHeight/2 );
Display.screenshot( bitmap, 0, 0, videoWidth / 2, videoHeight / 2 );

// Now setup video camera viewfinder
Player recorder = javax.microedition.media.Manager.createPlayer(
"capture://video?" + "encoding=video/3gpp&mode=standard");

if (recorder != null) {
recorder.prefetch();

VideoControl videoControl =
(VideoControl) recorder.getControl( "VideoControl" );

if (videoControl != null) {
// Use USE_GUI_PRIMITIVE since recorder returns a viewfinder
// Use USE_GUI_ADVANCED if player is returning a playback field
// in your app
final Field videoField = (Field) videoControl.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field" );

videoControl.setDisplaySize( videoWidth, videoHeight );
videoControl.setVisible( true );

// Must always update screen on the application event thread
Application.getApplication().invokeLater( new Runnable() {
public void run() {
// Order here matters, make sure viewfinder is always
// first field or manager added!
Screen myScreen = UiApplication.getUiApplication().getActiveScreen();

if (myScreen != null) {
// Insert viewfinder over entire screen at (0,0):
screenManager.insert( videoField, 0, 0, 0 );

// Add bitmap centered on viewfinder:
bitmapWindow.add( new BitmapField(bitmap), 0, 0 );
screenManager.add( bitmapWindow, videoWidth/4, videoHeight/4 );

// Dirty screen manager and bitmap window:
screenManager.invalidate();
bitmapWindow.invalidate();
}
}
});

recorder.start();
}
}
}
}

 

 

BVP

 

 

New Contributor
Posts: 3
Registered: ‎02-22-2011
My Device: 8830,8520,900,9700,9800
My Carrier: Mobile application developer

Re: AdvancedVideoControl not working as it should?

Works Great!! Thanks for your help mate!

New Contributor
Posts: 2
Registered: ‎09-26-2011
My Device: bold 9900
My Carrier: orange

Re: AdvancedVideoControl not working as it should?

Is it possible to play a video field over the camera feed instead of a bitmap field? I have been trying to do this with no joy - I just get a black square where the video should be playing.