How to Use Emacs to Play Music with EMMS

Emacs Music 00 Featured Image

Emacs is a brilliant program that can do many things including handling files. With the Emacs Multimedia System (EMMS) package, you can also handle your music in Emacs. You can easily browse music directories, create song playlists and even display lyrics. Here we will show you how to play music in Emacs.

Also read: 5 Hidden Features You Can Use to Improve Emacs

What is EMMS and How Does it Work?

EMMS is an Elisp front-end client for various multimedia players. This means that unlike traditional music players, EMMS only deals with displaying files and it uses external programs to decode those files.

Emacs Music 03 Sample Emms Session

EMMS consists of three distinct parts: the core, the player and the source.

  • The core – controls how files in an EMMS buffer should behave. Further, it also provides a way for other EMMS modules to read and manipulate those files.
  • The player – handles the interface between Emacs and the external music players.
  • The source – deals with how Emacs discovers and reads those files. It then puts those in an editable text buffer that the core part can read.

As a result, this approach allows you to treat each media file as text that you can easily copy to other Emacs buffers. For example, you can take a playlist from EMMS and either export it to an Org journal or a post to USENET through Gnus.

Emacs Music 04 Emms Text Copied To Buffer

Also read: How to Use Email within Emacs

Installing EMMS

With that, installing EMMS is incredibly easy. EMMS is already available in the GNU ELPA repository, so you can quickly install it:

  1. Press Alt + X then type package-install in your Emacs client.
  2. This will then bring up a small prompt where you can type the name of the package that you want to install. In this, you need to type emms then press Enter.
Emacs Music 06 Emms Run

Also read: 5 Useful Emacs Packages for Better Productivity

Configuring EMMS

With that done, you should create a simple configuration script for EMMS. Doing this will then allow EMMS to know which Emacs settings to enable as well as the external programs and file paths that it should look for.

  1. You can begin configuring EMMS by going to your Emacs’ “init.el” file. To do that, you need to press Ctrl + X, then Ctrl + F.
  2. This will then bring up a prompt where you can provide the file path that you want to edit. In this case, you need to provide the path: “/home/$USER/.emacs.d/init.el”.
Emacs Music 07 Open Emacs Config
  1. With that done, you then need to write the following lines of Lisp to your “init.el” file:
(require 'emms-setup)
(emms-all)
  1. This specific function tells EMMS to set and enable all the default settings, which allows you to play any media with the player.

Also read: 8 of the Best Linux Distros for Windows Users

Adding an External Music Player

By default, EMMS does not provide any media player for playback, the next thing you need to do is tell EMMS which media player it can use to play the audio that it indexes.

As such, you will need to first install a suitable media player if you want to play either FLAC or MP3 files.

  1. In our case, we’re installing mpv since it can play both audio and video files. Here’s how to go about it.
sudo apt install mpv
Emacs Music 08 Ubuntu Install Mpv
  1. Now, all you need to do is to write the following Lisp code to your “init.el” file:
(setq emms-player-list '(emms-player-mpv))

setq – Emacs function that allows you to set a particular variable’s value. In this case, you are modifying the value for the emms-player-list.

emms-player-list – a EMMS function that defines the list of media players that it can use.

emms-player-mpv – a specific glue function that links mpv and Emacs together. This is what allows EMMS to play your music inside Emacs.

Also read: How to Install Zoom on Linux

Adding a Default Music Directory

From there, the next thing that you need to do is to set the default directory where EMMS will look for media files. Similar to the other settings above, this also requires you to edit your “init.el” file.

Emacs Music 09 Emms Dired Music Files 1
  1. All you need to do is to add the following Lisp code:
(setq emms-source-file-default-directory "/path/to/directory")
  1. Once that’s out of the way, restart your Emacs installation to apply your new settings.

Starting a Basic EMMS Session

  1. You can now start EMMS by pressing Alt + X, then typing “emms”.
  2. Doing this will bring up a prompt where EMMS will ask you for the root path of the media that you want to play.
  3. For example, we will provide the path “/home/ramces/tmp/emacs-music” to tell EMMS that we want to play the files inside “emacs-music”.
Emacs Music 10 Emms Open Folder
  1. From there, EMMS will then create and display a simple playlist that contains all the playable media files inside that folder.

Also read: What Is Doom Emacs and How to Install It

Using the EMMS Playlist to Play Music in Emacs

  1. You can press Enter to start playing the first track in your playlist.
  2. When you had enough, stop this playback by pressing either Shift + P or S.
Emacs Music 11 Emms Playing Track
  1. Not only that, it is possible to switch between adjacent tracks in the playlist by pressing either P or N. This can be helpful if you want to skip the currently playing track.
Emacs Music 12 Emms Skip Track
  1. EMMS also allows you to rearrange the order of the tracks in your playlist. The way it works is that you can manipulate every text in an EMMS playlist similar to an Emacs text buffer. You can press Ctrl + Space, then Ctrl + W to yank off a track from your current playlist.
  2. From there, you can then scroll down and press Ctrl + Y to yank the line back to the list.
Emacs Music 13 Highlight And Copy Buffer
  1. It is also possible to clear the current playlist of any tracks. This can be especially useful if you either want to clear the list clean or create and save a new playlist. To do this, all you need to do is to press Shift + C.
Emacs Music 14 Clean Buffer

Creating a New Playlist in Emacs

EMMS also allows you to create custom playlists from inside Emacs. This means that, similar to traditional music players, you can save a specific list of music files that you want to play in sequence.

Emacs Music 15 Sample Playlist
  1. To do this, you need to first press Alt + X, then type “emms-playlist-new”.
  2. Doing this will then bring up an empty EMMS playlist where you can add new tracks.
Emacs Music 16 New Playlist
  1. From here, you need to set the blank playlist to be the current one. This will allow you to add new music tracks to the blank playlist. To do that, you need to press B while inside the blank EMMS buffer. This will then bring up a small prompt where you can press Enter to confirm the change.
Emacs Music 17 Switch Current Playlist To New
  1. Finally, open the EMMS browser to add the music file to your new playlist. For that, you need to press Alt + X again, then type “emms-browser”.
Emacs Music 18 Emms Music Browser
  1. Now, you can select the album or track that you want to add by pressing Enter.
  2. Once done, you can then go back to your new list and press Ctrl + X, then Ctrl + S to save it to a file.

Also read: How to Manage your Finances with Ledger Mode in Emacs

Music Scrobbling in Emacs with GNU FM

Aside from playing music, it is also possible to customize EMMS and extend its features beyond a simple media player. For example, you can use a function that allows you to upload track information to a music scrobbler such as libre.fm.

Emacs Music 19 Gnu Fm Website
  1. In order to enable this feature, you need to first open your “init.el” file.
  2. From there, you then need to add the following Lisp code after your EMMS configuration:
(require 'emms-librefm-scrobbler)
(setq emms-librefm-scrobbler-username "your-libre-fm-username"
      emms-librefm-scrobbler-password "your-libre-fm-password")

The first function – explicitly tells Emacs to load the GNU FM scrobbler for EMMS. This enables EMMS to connect to libre.fm and submit track information in its database.

The second function – contains your account information which EMMS uses to access libre.fm.

  1. The last thing that you need to do is to go back to EMMS. In there, you need to press Alt + X, then type “emms-librefm-scrobbler-enable”.
  2. This will enable the scrobbler plugin for this session and submit any tracks that you finish.
Emacs Music 20 Scrobbled Music

Also read: How to Use Emacs As a USENET Reader With Gnus

Frequently Asked Questions

Is it possible to use MPD with EMMS?

Yes! It is possible to use EMMS as a front-end client for MPD. All you need to do is to change the value of the “emms-player-list” variable in your “init.el” file.

Is it possible to play music files over the network in Emacs?

Sadly, no. While Emacs supports network file mounting, EMMS cannot use this specific feature. This is because EMMS is only built to handle local files. As such, there is no native way to play music located on a different machine through EMMS. One way to get around this limitation is to create a network mount outside Emacs. For example, you can run the following command which uses SSHFS to create a network mount to your home directory:

sshfs remoteuser@remotemachine:/path/to/music /home/$USER/

Aside from external network mounts, EMMS also supports network radio streams. To enable this, all you need to do is to press Alt + X, then type “emms-streams”.

Is it possible to search through the EMMS browser?

Yes! It is possible to search through all the files present in your EMMS browser. To do this, you need to press S, then T while inside the browser buffer. This will then bring up a small prompt where you can provide the track that you want to play. Further, EMMS also allows you to search through its database using other metadata values. For example, you can press S then A to search using the artist’s name.

Image credit: Unsplash All screenshots by Ramces Red

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.