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

Native Development

Reply
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer

Video playing on playbook from QT

Hello All,

 

I am trying to play a video file from My QT app on playbook.

I am developing application specific to the playbook so to play a video I had used native multimedia api to play a video.

 

On a click of button I had called a slot and in that my code is

   


 #ifdefined(Q_OS_QNX)
qDebug()<<"inside QNX";
// I/O devices

static
constchar*video_device_url="screen:?winid=videosamplewindowgroupwingrp=videosamplewindowgroup";staticconstchar*audio_device_url="audio:default";
// Name of video context
static
constchar*video_context_name="samplevideocontextname";
// Window group name

static
constchar*window_group_name="videosamplewindowgroup";
int
rc;
int
exit_application=0;
 // Screen variables
screen_context_tscreen_context=0;
screen_window_tscreen_window=0;
int
size[2]={0,0};
// Renderer variables

mmr_connection_t*mmr_connection=0;
mmr_context_t*mmr_context=0;
// I/O variables

int
video_device_output_id=-1;
int
audio_device_output_id=-1;
bps_initialize();
/*
 * Create the window used for video output.
 */

if
(screen_create_context(&screen_context,SCREEN_APPLICATION_CONTEXT)!=0){
qDebug("Error at 1");
return
EXIT_FAILURE;
}

if
(screen_create_window(&screen_window,screen_context)!=0){
screen_destroy_context(screen_context);
qDebug("Error at 2");
return
EXIT_FAILURE;
}

if
(screen_create_window_group(screen_window,window_group_name)!=0){
qDebug("Error at 3");
return
EXIT_FAILURE;
}

int
format=SCREEN_FORMAT_RGBA8888;if(screen_set_window_property_iv(screen_window,SCREEN_PROPERTY_FORMAT,&format)!=0){qDebug("Error at 4");
return
EXIT_FAILURE;
}

int
usage=SCREEN_USAGE_NATIVE;if(screen_set_window_property_iv(screen_window,SCREEN_PROPERTY_USAGE,&usage)!=0){qDebug("Error at 5");
return
EXIT_FAILURE;
}

if
(screen_create_window_buffers(screen_window,1)!=0){
qDebug("Error at 6");
return
EXIT_FAILURE;
}

/*
 * Configure mm-renderer.
 */

mmr_connection=mmr_connect(NULL);
if
(mmr_connection==NULL){
qDebug("Error at 7");
return
EXIT_FAILURE;
}

mmr_context=mmr_context_create(mmr_connection,video_context_name,0,S_IRWXU|S_IRWXG|S_IRWXO);if(mmr_context==NULL){
qDebug("Error at 8");
return
EXIT_FAILURE;
}

/*
 * Configure video and audio output.
 */

video_device_output_id=mmr_output_attach(mmr_context,video_device_url,"video");
if
(video_device_output_id==-1){
qDebug("Error at 9");returnEXIT_FAILURE;
}

audio_device_output_id=mmr_output_attach(mmr_context,audio_device_url,"audio");if(audio_device_output_id==-1){
qDebug("Error at 10");
return
EXIT_FAILURE;
}

// Get the render buffer

screen_buffer_ttemp_buffer[1];
if
(screen_get_window_property_pv(screen_window,SCREEN_PROPERTY_RENDER_BUFFERS,(void**)temp_buffer)!=0){
qDebug("Error at 11");
return
EXIT_FAILURE;
}
//Fill the buffer with a solid color (black)
int
fill_attributes[3]={SCREEN_BLIT_COLOR,0x0,SCREEN_BLIT_END};
if
(screen_fill(screen_context,temp_buffer[0],fill_attributes)!=0){
qDebug("Error at 12");
return
EXIT_FAILURE;
}

// Make the window visible

if
(screen_get_window_property_iv(screen_window,SCREEN_PROPERTY_SIZE,size)!=0){
qDebug("Error at 13");
return
EXIT_FAILURE;
}

int
temp_rectangle[4]={0,0,size[0],size[1]};if(screen_post_window(screen_window,temp_buffer[0],1,temp_rectangle,0)!=0){
qDebug("Error at 14");
return
EXIT_FAILURE;
}

// Prevent the backlight from going off

int
idle_mode=SCREEN_IDLE_MODE_KEEP_AWAKE;if(screen_set_window_property_iv(screen_window,SCREEN_PROPERTY_IDLE_MODE,&idle_mode)!=0){
qDebug("Error at 15");
return
EXIT_FAILURE;
}

// Build up the path where our bundled resource is.

char
cwd[PATH_MAX];
char
media_file[PATH_MAX];
getcwd(cwd,PATH_MAX);
printf(cwd);
rc=snprintf(media_file,PATH_MAX,"file://%s/app/native/0_66370600_1328196991.mp4",cwd);
if
((rc==-1)||(rc>=PATH_MAX)){
qDebug("Error at 16");
return
EXIT_FAILURE;
}

/*
 * Start the playback.
 */

if
(mmr_input_attach(mmr_context,media_file,"track")!=0){
qDebug("Error at 17");
return
EXIT_FAILURE;
}

if
(mmr_play(mmr_context)!=0){
qDebug("Error at 18");
return
EXIT_FAILURE;
}

screen_request_events(screen_context);
navigator_request_events(0);
 /*
* Handle keyboard events and stop playback upon user request. */

for
(;;){
bps_event_t*event=NULL;
if
(bps_get_event(&event,-1)!=BPS_SUCCESS){
qDebug("Error at 19");returnEXIT_FAILURE;
}
if(event){
 if(bps_event_get_domain(event)==navigator_get_domain()&&bps_event_get_code(event)==NAVIGATOR_EXIT){
exit_application=1;}
if
(exit_application){qDebug("Error at 20 exit app");
break
;}}}
screen_stop_events(screen_context);
if
(mmr_stop(mmr_context)!=0){
qDebug("Error at 21");
return
EXIT_FAILURE;
}

if(mmr_output_detach(mmr_context,audio_device_output_id)!=0)
{

qDebug("Error at 22");
return
EXIT_FAILURE;
}

if(mmr_output_detach(mmr_context,video_device_output_id)!=0){
qDebug("Error at 23");
return
EXIT_FAILURE;
}

if(mmr_context_destroy(mmr_context)!=0){
qDebug("Error at 24");
return
EXIT_FAILURE;
}

mmr_context=0;
video_device_output_id=-1;
audio_device_output_id=-1;
mmr_disconnect(mmr_connection);
mmr_connection=0;
 bps_shutdown();
if(screen_destroy_window(screen_window)!=0){
qDebug("Error at 25");
return
EXIT_FAILURE;
}

if(screen_destroy_context(screen_context)!=0){
 qDebug("Error at 26");
return
EXIT_FAILURE;
}
screen_context=0;
screen_window=0;
return
EXIT_SUCCESS;
#endif
}

 

I am not getting any output with this code. and my application is being hang on the click of button.

This code works well in the native application.

 

in .pro file i had included the native library

  

BB_NDK=d:/bbNDK2.0
INCLUDEPATH+=$$BB_NDK/target/qnx6/usr/include
LIBS
+=-lbps
LIBS
+=-lscreen
LIBS
+=-lmmrndclient
LIBS
+=-lstrm

Developer
jheron
Posts: 188
Registered: ‎01-27-2012
My Device: playbook

Re: Video playing on playbook from QT

Whoa! That's allot of code to play a video eh!

I am sorry I don't know much about the multimedia api. but have you tried:

QDesktopServices::openUrl(QUrl("file://%s/app/native/0_66370600_1328196991.mp4", QUrl::TolerantMode));

Just a suggestion, I have not tried that...

Good luck!

Jon

 

 

Developer
mzex
Posts: 368
Registered: ‎06-30-2012
My Device: Playbook, Z10LE, DevAlpha C

Re: Video playing on playbook from QT

[ Edited ]

I am having similar problems , i have code which runs OK natively, but fails on QT application. Problem is that your code probably works, but its window is below QT app window and you cant see it.

If you put this code inside your "Create window" snippet

 

 int z = 10 ; 
 screen_set_window_property_iv(screen_win,SCREEN_PROPERTY_ZORDER, &z);

 

you will probably get your video player visible, but will make a mess with navigator events, and probably app will freeze.

 

Way to do it is with "ForeignWindow" which we have in Cascades. Look at newest sample in Cascades "Payment API", you will see that inside that foreign window is shown some native window. I'm still struggling with my code and having exactly same problem like you, native window cant be shown over QT window. I'm trying to replicate that foreign window behaviour from cascades sample into common QT.

 

If you find some other solution, keep us informed.

 

Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer

Re: Video playing on playbook from QT

Sorry For replying late.

Actually I want to run my app pnly in playbook not on bb10. So option of cascades is not possible. I will try with first one.

Developer
mzex
Posts: 368
Registered: ‎06-30-2012
My Device: Playbook, Z10LE, DevAlpha C

Re: Video playing on playbook from QT

I'm having similar problems, and i don't want to use Cascades either, i was thinking to make something similar like Foreign window in Cascades.

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Video playing on playbook from QT

I don't have a Qt environment set up so I can't try out your code, nor do I know much about how Qt is architected, but I imagine that your code is being invoked from a Qt event loop thread of some sort.

 

It looks like you're trying to implement your own event loop in the for(;:smileywink: section of your code.

 

Since your function doesn't return, I imagine the Qt UI and/or event threads are just blocked because you have a forever-loop.

 

I suggest spawning a new thread to run this code so that you don't block the Qt thread that invoked your function.  Alternately, I highly suggest making use of whatever existing event loop infrastructure exists in Qt rather than trying to run your own navigator/screen event loop yourself.  I have a suspicion that this may cause a race/starvation condition.

Also, if you put this window in front of Qt's application window, I'm not sure that any touch events will be delivered to the "bottom" window.

 

Cheers,

Sean