Playing playlists

Updated: April 19, 2023

You can attach playlist files as inputs, to play multiple audio or video tracks in sequence. You can also configure parameters for the entire playlist or specific entries (tracks).

Note: Playlists aren't supported in the shipped version of mm-renderer. If you need this capability, contact QNX Customer Support. If you want to use HTTP Live Streaming (HLS) playlists, you must also obtain special support for this feature.

This sample program attaches a video playlist file as the input, and enables repeating of the entire playlist and pausing between video tracks. After starting playback, the program changes the repeat setting for a particular track.

Defining a playlist input

After configuring an mm-renderer context for video playback, we attach a playlist input with a URL that names a video playlist file:
/* Code to connect to mm-renderer and create a context goes here 
   (see "Playing audio content" for an example of doing so) */

/* Code to attach video and audio outputs to support video playback
   goes here (see "Playing video content" for an example of doing so */

// Attach a video playlist file as a "playlist" input
int inputID = mmr_input_attach( ctxt_videoplaylist_play,
                                "/fs/usb0/vancouver2010_highlights.m3u",
                                "playlist" );

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

For the input URL, we provide a hard-coded path to a local M3U playlist file. In your program, you might need to use a variable; for example, if the playlist 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. In its simplest form, an M3U file is a plain-text file containing the pathnames or URLs of the tracks to play (one per line). For the list of supported playlist types and their associated file extensions, see the product release notes.

We could also provide an SQL URL in this form:
sql:database?query=query
where database is the full path to an SQLite database file and query is an SQL query that produces a single results column that contains URLs in a form acceptable for the track input type. Note that any special characters in the query must be URL-encoded (e.g., spaces encoded as %20).

Configuring input parameters for the playlist

The mm-renderer service supports continuous replay of entire playlists or specific tracks in them. In our example, we set the repeat input parameter so that all videos (i.e., the entire playlist) are replayed in sequence, continuously. We also set transition_speed to pause playback at track boundaries.
strm_dict_t* dict_input_params = strm_dict_new();

// Enable continuous playback of entire sequence of videos
if ( strm_dict_set( dict_input_params, 
                    "repeat", 
                    "all" ) < 0 ) {
    /* Error-handling code goes here */
}
// Pause playback when beginning of next video is reached
else if ( strm_dict_set( dict_input_params, 
                         "transition_speed", 
                         "0" ) < 0 ) {
    /* Error-handling code goes here */
}
else if ( mmr_input_parameters( ctxt_videoplaylist_play,
                                dict_input_params ) < 0 ) {
    /* Error-handling code goes here */
    return EXIT_FAILURE;
}

Either of these parameters can be set before or after attaching the input, and even after starting playback. When a track finishes playing, mm-renderer either stops playback or jumps to the next track in the playlist, depending on the repeat setting. Then, the service changes the playback speed based on the transition_speed setting. Our program starts playing the entire playlist in a continuous loop (because repeat is all), but pauses each time a new track begins (because transition_speed is 0).

This second parameter setting lets us pause playback at track boundaries without calling mmr_speed_set(). This in turn lets our application wait for a system event or user action requesting that playback be resumed. We would then have to call mmr_speed_set() with a speed setting of 1000 to play at normal speed, or a different value to play faster, slower, or backwards.

The “Defining parameters” section lists the supported values for these two parameters.

Configuring track parameters for the playlist

Suppose sometime during playback we decide to play a particular track continuously. We want to replay that track only, not the entire playlist, so we set repeat as a track parameter, while providing the playlist index of the track we're configuring:
// Enable continuous playback of a specific track
if ( strm_dict_set( dict_track_params, 
                    "repeat", 
                    "all" ) < 0 ) {
    /* Error-handling code goes here */
}
else if ( mmr_track_parameters( ctxt_videoplaylist_play,
                                curr_idx,
                                dict_track_params ) < 0 ) {
    /* Error-handling code goes here */
    return EXIT_FAILURE;
}