Audio Framework

From Navit's Wiki
Jump to: navigation, search

The Audio Framework provides functionality to play music from within navit. That is intended to be used in embedded systems and was developed on and for the Raspberry Pi but will work on any linux based embedded system. An audio player is loaded as plugin where navit can have multiple audio plugins loaded at the same time. Only one player plugin should be active at a time or music experience will suffer. A little. The Audio Framework uses alsalib to play music and access the music volume. So libasound2-dev must be installed on the target before starting the compile process.



The audio player provides a GUI for the playlists of the music. There you are able to select a certain song or album to play, toggle playback, shuffle and repeat, and of course switch artists and playlists. You are also able to view your playlists. To enable the GUI, add an icon to gui internal (i.e. add to Main Menu):

<gui type="internal" enabled="yes" icon_xs="8" icon_s="16" icon_l="48"  fullscreen="1" font_size="200"><![CDATA[<html>
	<a name='Main Menu'><text>Main menu</text>
	<img src='music-player' onclick='media_show_playlist()'><text>Music</text></img>
Rootlist showing the available Playlists
Gui showing the content of a playlist


The Audio Framework has its own OSD item. If you place an OSD item to navit.xml, you will see the currently playing song and playlist. The minimal configuration is:

<osd enabled="yes" type="audio_player"/>

which will print a string with "Track - Artist - Album"

You can set the label attribute to separate track name from playlist name where

<osd enabled="yes" type="audio_player" label="playlist"/>

prints "Artist - Album" which should generally be used as playlist name and

<osd enabled="yes" type="audio_player" label="track"/>

prints "Track"

Audio OSDs running on an embedded device (RaspberryPi, 320x234px display) The top OSD is labelled playlist and the underneath is track.


The Audio Framework introduces a bunch of attributes to be able to send data through navit. They are used to show the players status on an OSD for example. There exist three communication attributes currently

<playing> keeps the playing status (0=paused, 1=playing)

<shuffle> keeps the shuffle information where

0=no shuffle,

1=shuffle playlist (any track of the current playlist),

2=chooses a playlist randomly from the music directory (any playlist ordered from the music directory),

3=shuffle playlists and tracks on the randomly chosen playlist (any track of any playlist)

<repeat> keeps the repeat information where

0=no repeat,

1=no repeat,

2=repeat the currently chosen track,

3=repeat the currently chosen playlist

Player Types[edit]

MPD Player[edit]

The MPD Player is a player that uses MPD and MPC to play local audio files like MP3 audio.

To access the player it must be activated in navit.xml and the directory must be set, where navit will search for music files.

<audio type="player-mpd" music_dir="/path/to/music" />


Since the MPD player uses Music Player Deamon, MPD must be installed and configured correctly to play music. Additionally mpc, the Music Player Deamon Client is used as middleware to send commands to MPD through command line. So it must be installed, too.

Music Directory[edit]

It is needed to specify a Music Directory for the Player to search for Music. This might be a USB flash device which is mounted on startup. Assuming mount point /mome/user/stick, you may want to add this line to /etc/fstab:

/dev/sda1   /home/user/stick   vfat   defaults   0   2

You might want to check if this is really working for your setup.

Add a folder music to the USB drive

$ cd /home/user/stick
$ mkdir music

Add your Music to music. Use a folder for each Album names with name "Artist - Album". Example: "Marilyn Manson - Holy Wood"

If you have subfolders with CD1, CD2, ... or something like "Album" and "Bonus", the songs inside the subfolders will be merged to one playlist which orders the music after their ID3-Tags.


On navit startup the music directory is scanned and all the music is loaded to the player. The music player uses an external program to care about music organisation to be able to schedule load for multiple cores of the targeted hardware.

Note: The Folders which contain the mp3-files should be named a special way to make the "switch artist" function work. The Folder names should be UTF-8 coded and be named "Artist - Album". "Artist-Album" or "Album - Artist" would break the function but everything else should work. For this function the String before the '-' is compared.

Spotify Player[edit]

To use the spotify plugin, you will need a spotify premium account (this does not work with the Free account).

  • An item in red is currently offline (not cached)
  • An item in blue is scheduled to be downloaded
  • An item in orange is currently being downloaded
  • An item in green is in cache, so you can listen to it offline.

When starting playback of a playlist, all the playlist will be automatically cached.

To enabled this plugin, add an entry like this in your navit.xml :

<audio type="player-spotify" spotify_login="<yourlogin>" spotify_password="<yourpass>" spotify_playlist="<default playlist>" audio_playback_pcm="sysdefault:CARD=PCH"/>

The playlists view :


The tracks view :


Making your own player[edit]

To be able to easily understand the functions of the audio framework, there is a "Stub Player" inside the source tree, which will be compiled if activated through cmake prebuild. Copy and rename it and add your code to the player. The Stub Player is a working implementation without real music functionaity but with GUI, attribute and OSD functionality. You'll need an (external - make easy use of multicore processors) library for decoding and playing the audio. The Player should care about playlist management and the commands to get the music playing.