Updated: October 28, 2024 |
You can treat a single track as a playlist, meaning you can repeat playback. This is useful when your existing code uses playlists and you want to adapt it to play single songs or videos.
The code sample here attaches an audio output, sets the repeat input parameter to enable continuous playback of a track, then attaches an autolist input that names a local audio file to treat as a playlist.
/* 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 an audio output with a URL of "snd:" to use the preferred device int outputID = mmr_output_attach( ctxt_audioplay, "snd:", "audio" ); if (outputID == -1) { errorInfo = mmr_error_info(ctxt_audioplay); /* Remaining error-handling code goes here */ return EXIT_FAILURE; } strm_dict_t* dict_input_params = strm_dict_new(); // Enable continuous playback if ( strm_dict_set( dict_input_params, "repeat", "track" ) < 0 ) { /* Error-handling code goes here */ } else if ( mmr_input_parameters( ctxt_audioplay, dict_input_params ) < 0 ) { errorInfo = mmr_error_info(ctxt_audioplay); /* Remaining error-handling code goes here */ return EXIT_FAILURE; } // Attach a local audio file as an "autolist" input, to treat the // single track as a playlist int inputID = mmr_input_attach( ctxt_audioplay, "/fs/usb0/stillness_in_time.mp3", "autolist" ); if (inputID == -1) { errorInfo = mmr_error_info(ctxt_audioplay); /* Remaining error-handling code goes here */ return EXIT_FAILURE; }
// Disable continuous playback if ( strm_dict_set( dict_track_params, "repeat", "none" ) < 0 ) { /* Error-handling code goes here */ } else if ( mmr_track_parameters( ctxt_audioplay, 1, dict_track_params ) < 0 ) { errorInfo = mmr_error_info(ctxt_audioplay); /* Remaining error-handling code goes here */ return EXIT_FAILURE; }
The mm-renderer service uses the repeat setting defined through mmr_input_parameters() as the initial setting for any track in the input playlist. With autolist, the playlist consists of a single media file or stream, but it must still be configured as a playlist entry using mmr_track_parameters().