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
New Contributor
Posts: 3
Registered: ‎03-26-2012
My Device: Playbook 2.0
My Carrier: Rogers

Using Video Screen alongside classic QWidget

[ Edited ]

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=videosamplewindowgroup";
    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

BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Using Video Screen alongside classic QWidget

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.

New Contributor
Posts: 2
Registered: ‎07-05-2012
My Device: Playbook

Re: Using Video Screen alongside classic QWidget

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

BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Using Video Screen alongside classic QWidget

Video can only be played from a file or from a URL via a playlist. Static byte arrays of video would result in your app consuming more memory than it needs to.
Highlighted
New Contributor
Posts: 7
Registered: ‎07-06-2012
My Device: Playbook
My Carrier: 6136009997

Re: Using Video Screen alongside classic QWidget

What was the solution for this problem, can you please share?
New Contributor
Posts: 3
Registered: ‎03-26-2012
My Device: Playbook 2.0
My Carrier: Rogers

Re: Using Video Screen alongside classic QWidget

For now I haven't found solution. Using Video in my application is in standby. However, I'm interested by a solution...