03-26-2012 02:05 PM - edited 03-26-2012 02:16 PM
Hi,
I'm trying to get workind a video playback with a Qt application.
I designed my Qt application with QtCreator. It's working great and I'm able to use BPS Sensors correctly using QThread.
For the next step, I need to implement a videoplayer in my application.
I first tried with QMovie, however, it seems not having necessary codecs to read mp4 files without Phonon which is unsupported.
I then tried to do it with the native SDK. I took the code from Video Playback sample and putted it into a Slot.
void Widget::on_btnVideo_clicked()
{
this->setVisible(false);
this->setGeometry(0,0,0,0);
// I/O devices
static const char *video_device_url = "screen:?winid=videosamplewindowgroup&wingrp=video samplewindowgroup";
static const char *audio_device_url = "audio:default";
// Name of video context
static const char *video_context_name = "samplevideocontextname";
// Window group name
static const char *window_group_name = "videosamplewindowgroup";
int rc;
int exit_application = 0;
// Screen variables
screen_context_t screen_context = 0;
screen_window_t screen_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) {
return /*EXIT_FAILURE*/;
}
if (screen_create_window(&screen_window, screen_context) != 0) {
screen_destroy_context(screen_context);
return /*EXIT_FAILURE*/;
}
if (screen_create_window_group(screen_window, window_group_name) != 0) {
return /*EXIT_FAILURE*/;
}
int format = SCREEN_FORMAT_RGBA8888;
if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) {
return /*EXIT_FAILURE*/;
}
int usage = SCREEN_USAGE_NATIVE;
if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) {
return /*EXIT_FAILURE*/;
}
if (screen_create_window_buffers(screen_window, 1) != 0) {
return /*EXIT_FAILURE*/;
}
/*
* Configure mm-renderer.
*/
mmr_connection = mmr_connect(NULL);
if (mmr_connection == NULL) {
return /*EXIT_FAILURE*/;
}
mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
if (mmr_context == NULL) {
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) {
return /*EXIT_FAILURE*/;
}
audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
if (audio_device_output_id == -1) {
return /*EXIT_FAILURE*/;
}
// Get the render buffer
screen_buffer_t temp_buffer[1];
if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) {
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) {
return /*EXIT_FAILURE*/;
}
// Make the window visible
if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, size) != 0) {
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) {
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) {
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);
rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/videos/pb_sample.mp4", cwd);
if ((rc == -1) || (rc >= PATH_MAX)) {
return /*EXIT_FAILURE*/;
}
/*
* Start the playback.
*/
if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
return /*EXIT_FAILURE*/;
}
if (mmr_play(mmr_context) != 0) {
return /*EXIT_FAILURE*/;
}
screen_request_events(screen_context);
navigator_request_events(0);
/*for (;;) {
bps_event_t *event = NULL;
if (bps_get_event(&event, -1) != BPS_SUCCESS) {
return EXIT_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) {
break;
}
}
}*/
//screen_stop_events(screen_context);
/*if (mmr_stop(mmr_context) != 0) {
return EXIT_FAILURE;
}
if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
return EXIT_FAILURE;
}
if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
return EXIT_FAILURE;
}
if (mmr_context_destroy(mmr_context) != 0) {
return /XIT_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) {
return EXIT_FAILURE;
}
if (screen_destroy_context(screen_context) != 0) {
return EXIT_FAILURE;
}
screen_context = 0;
screen_window = 0;
*/
return /*EXIT_SUCCESS*/;
}I still need to fix the part that is commented but I won't do it until I make first working video playback...
First, the window seems to appear behind my QWidget window as I can hear the sound from the video. If I close de QWidget window (this->close()), focus goes to the black screen. I can still hear the sound but i can't see anything....
I tried to set QWidget invisible with setVisible(false) or hide() but no one is working.
How could I fix that ?
Thanks
05-09-2012 11:41 AM
Hi.
As was described in a couple of the demo sessions last week at BlackBerry 10 Jam last week, videos are rendered into a child window and the only way to see that window is to create a "hole" in the window in front of it to show throuigh. Cascades introduced a component called a ForeignWindow to do this. You would need a transparent background in your app screen to perform something similar with your project.
07-05-2012 02:43 PM
Hi globtech did you found a way to solve that problem? Would you mind sharing the solution? I would like also to ask if there is a way to play a dinamic byteArray instead of a static video file.
Thanks for your attention.
Camilo Campos
07-06-2012 01:27 AM
07-06-2012 09:44 AM
07-09-2012 09:11 AM
For now I haven't found solution. Using Video in my application is in standby. However, I'm interested by a solution...