Playing video content

Updated: April 19, 2023

To prepare for playing a video track, you must follow the same steps as when setting up audio playback. But you must use the Screen API instead of mm-renderer to configure output parameters; doing so gives you control over how and when content is displayed.

Note: Playing an HTTP file or HTTP Live Streaming (HLS) stream isn't supported in the shipped version of mm-renderer. If you need these capabilities, contact QNX Customer Support.

The code excerpts below show how to give mm-renderer an output URL of screen: to render video content on the full display, and an input URL that names a local video file or a network-accessible stream for playback. These scenarios demonstate a simple case when you want to use the full display because no other UI apps are running. At other times, you may want to restrict the content to a particular area, which requires using the Screen API and is demonstrated in Managing video windows.

Configuring mm-renderer to play a video file

We first connect to mm-renderer and create a context, then tell direct the output to Screen:
/* Code to connect to mm-renderer and create a context goes here 
   (see "Playing audio content" for an example of doing this) */
const mmr_error_info_t* errorInfo;

// Attach a video output with a URL of "screen:" to use the full display
int outputID = mmr_output_attach( ctxt_videorec, "screen:", "video" );

if (outputID == -1) {
    errorInfo = mmr_error_info(ctxt_videorec);
    /* Remaining error-handling code goes here */
    return EXIT_FAILURE;
}
Nearly all videos have an audio component. The next step is to attach the audio output to the context:
// Attach an audio output with a URL of "snd:" to use the preferred device
audio_device_output_id = mmr_output_attach( ctxt_videorec, 
                                            "snd:", 
                                            "audio" );

if (audio_device_output_id == -1) {
    errorInfo = mmr_error_info(ctxt_videorec);
    /* Remaining error-handling code goes here */
    return EXIT_FAILURE;
}

Using mmr_output_parameters(), you can configure any of the audio output parameters described in Parameters that affect how the output is delivered.

Defining the input and starting playback

We now attach the input by providing a URL that names the video file we want to play:
// Attach a local file as the input; use "track" as the type because
// we're playing a single video track
int inputID = mmr_input_attach( ctxt_videorec,
                                "/fs/usb0/shape_of_you_video.mpg",
                                "track" );

if (inputID == -1) {
    /* Error-handling code goes here */
    return EXIT_FAILURE;
}

if ( mmr_play( ctxt_videorec ) < 0 ) {
    /* Error-handling code goes here */
    return EXIT_FAILURE;
}

For the input URL, we provide a hard-coded path to a local MPEG video file. In your program, you might need to use a variable; for example, if the track to be played is based on user selection. Also, when naming a file as input, you can prepend the URL with file: to make it clear that you're accessing a file. For the list of supported file extensions and associated video formats, see the product release notes.

The mm-renderer service also allows your application to act as an RTP or RTSP streaming client. If a stream has an MP3TS format, you can use an rtp: URL that lists the port on which the stream is delivered. The port number can be prefixed with an IP address and a colon:
rtp://10.222.97.225:49152
Or, if the server is local, an AT sign can be used in place of the IP address:
rtp://@:49152

If the streaming server supports RTSP, using a standard rtsp: URL gives you access to any functionality that RTSP adds to RTP, such as playback on demand, pausing, seeking, and authentication (if your server supports them). See your server's documentation for details.

If the streaming server provides an SDP description of the RTP stream through a local file, you can use a file: URL. When you attach such an input, mm-renderer connects to the RTP server listed in the file to receive the data over RTP.

Controlling playback

When playing a video file, you can manage playback in the same way as when playing an audio file.