Using mmcli to play media files

The following mmcli interactive sessions demonstrate common use cases for playing media files with mm-renderer. The command sequences shown here don't correspond exactly to the API calls needed if you're using mm-renderer directly, but do show the configuration steps required to define a media flow, configure parameters, and control playback.

Playing an audio file

To start playing an audio file located on a USB stick over the default audio device, enter a command sequence like this:
# mmcli -i mmrenderer_cli.so

> OutputAttach audio:default audio
018.965 Command 'OutputAttach':
ID: 0
> InputAttach /fs/usb0/tunes/arcade_fire/sprawl(II).wma track
> Play

The OutputAttach command defines an audio output for mm-renderer by specifying a URL of audio:default and an output type of audio. This URL tells mm-renderer to use automated audio routing with the Audio Manager service. Because you can define many outputs, mm-renderer returns an output ID (shown on the following line) when you attach one, so you can distinguish it from the others. You must attach all outputs before attaching the input because mm-renderer sometimes determines whether it can play an input based on the output types.

Next, the InputAttach command provides a URL with the path of a WMA file stored on a device mounted to /fs/usb0, and specifies the track input type (because the input is a single track to be played in isolation). The Play command then starts playback.

In this first example, the mmrenderer_cli.so library is loaded using -i when mmcli is launched. This ensures that the mm-renderer API is available from the start of the interactive session. You could also load the library just after launching mmcli, as follows:
# mmcli

> load mmrenderer_cli.so
> OutputAttach audio:default
...
When an audio track is playing, you can adjust its speed (with SpeedSet), seek to a new position (with Seek), and stop playback (with Stop). For instance, after starting playback, you can give the following commands:
> SpeedSet 0
> Seek 30000
> SpeedSet 1000
> Stop

This sequence pauses playback (by setting its speed to 0), seeks to a new position 30 seconds from the track start (as indicated by the 30000 value, which specifies the offset in milliseconds), resumes playback at normal speed, and finally stops playback. It's not necessary to pause playback before seeking to a new position; this was done just as an example of playback control.

Playing a video file

To play a video file stored on the local hard drive, enter commands like this:
# mmcli -i mmrenderer_cli.so

> OutputAttach screen: video
018.965 Command 'OutputAttach':
ID: 0
> OutputAttach snd:/dev/snd/pcmPreferredp audio
018.965 Command 'OutputAttach':
ID: 1
> OutputParameters 1 volume=30
> InputAttach /tmp/video/abilodeau_gold_medal_run.mp4 track
> Play

Here, two outputs are attached—one for the video component, which is rendered by Screen, and another for the audio component, which is outputted over the preferred audio device (e.g., a speaker). The output type must be given when calling OutputAttach for each component. Each output is given a distinct ID, which is displayed on the following line. The volume of the audio output (whose ID is 1) is set to 30 with the OutputParameters command. Next, the InputAttach command provides an input URL for a video file found in /tmp/video/. Finally, the Play command starts playing the video and audio components.

Playing a different media file

When you've finished playing one file and want to play another one, you must detach the current input and output and then attach a new output before attaching a new input:
> InputDetach
> OutputDetach 0
> OutputDetach 1
> OutputAttach
018.965 Command 'OutputAttach':
ID: 2
> InputAttach /tmp/audio/killers/when_you_were_young.mp3

The InputDetach command requires no parameters because only one input can be set but OutputDetach requires the ID of the output being detached. You must call OutputDetach for each attached output. After giving these commands, you can define a new media flow by attaching one or more new outputs and then the new input.