08-11-2011 08:43 PM
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/vide os/sample.mp4");
p.realize();
AdvancedVideoControl vc;
if ((vc = (AdvancedVideoControl) p.getControl("net.rim.device.api.media.control.Adv ancedVideoControl")) != null) {
videoField = (Field) vc.initDisplayMode(AdvancedVideoControl.USE_GUI_AD VANCED, "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());
}
Solved! Go to Solution.
08-19-2011 10:29 AM - edited 08-19-2011 10:30 AM
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:
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.
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.
08-19-2011 08:11 PM
Putting all fields in a ComponentCanvas did it. Working beautifully now. Thanks a lot!
08-24-2011 05:50 AM
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.
08-25-2011 11:18 AM - edited 08-25-2011 11:19 AM
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
08-26-2011 07:09 AM
Works Great!! Thanks for your help mate!
09-28-2011 05:02 AM
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.