Note that you can have as many AlsaPlayer objects as you want but each one must have a unique alsa device name.

  use AlsaPlayer;
  my $mp3_player = new AlsaPlayer('mp3_player', 'alsa_device_name');

  use PlayList;
  my $kirk_mp3s = new PlayList;

  if ($Reload) {
    # Starts the Alsaplayer process

    # Populate the playlist

    # Start playing the MP3s

If you want randomized playlist, you can call the randomize() function on the PlayList object before adding it to the player but after populating it with MP3s. Instead (or in addition to), you can call shuffle(1) on AlsaPlayer before adding any playlists. This requires you to have patched your AlsaPlayer as described just above the shuffle function in this module.


Allows the full creation and control of alsaplayer processes on your system. I use this with a M-Audio Delta 410 and the Linux ALSA drivers to create up to four simultaneous stereo MP3 streams. I then connect those outputs to my Netstreams Musica whole-house audio system to provide customized music throughout my house.

You can get the most current version of this file and other files related whole-house music/speech setup here:


This Misterhouse module assumes the 'alsaplayer' program is installed and operational as the Misterhouse user. Since I run mine in real-time mode, and local security is not a big issue, I have my binary set setuid root (owned by root and mode 4555). You can help improve performance by telling alsaplayer to not load ID3 tags from MP3s by modifying its configuration file (.alsaplayer/config in your home directory) and setting 'mad.parse_id3' to false. I do this when I'm running MP3s off of a network drive.

Usage Details:

Input States: The object accepts the following input states:

 - next: Go to the next song
 - previous: Go to the previous song
 - pause: Pause the player
 - unpause: Resume the player

Output States: You can watch for the following states from an AlsaPlayer object:

 - new_song: Player just started playing a new song.
 - playlist_loaded: Player just finished loading the current playlist


 - Have not implemented seeking/jumping to points in a MP3 (--seek and --relative)
 - Have not implemented variable speed (--speed)
 - Have not implemented the ability to jump straight to a specific track (--jump)


 - The alsaplayer processes are not stopped when Misterhouse exits, but you could kill them by running 'killall alsaplayer' upon shutdown.  This module attempts to reconnect with players through restarts, but if there are problems you may want to do a 'killall alsaplayer' followed by a 'rm /tmp/alsaplayer*'.


 - Since the command-line of Alsaplayer only has '--pause' (toggle) and --play, this module attempts to keep track of the pause state, but sometimes it can get it wrong.  So, it is best to set up a remote or voice command to allow you to manually pause/resume the MP3s...
 - I believe the file ~/.alsaplayer/alsaplayer.m3u will mess things up and I recommend removing it before starting up Misterhouse.

Special Thanks to: Bruce Winter - Misterhouse





Starts the process and/or resumes playing


Stops playing


removes all PlayList objects (and pauses the player).


adds a PlayList object to this player's MP3 queue


removes a PlayList object from this player's MP3 queue


Unpauses the player


Pauses the player


Pauses or unpauses the player


Jumps forward the specified number of seconds.


Jumps back the specified number of seconds.


Returns current paused status


Jump to the next song in the playlist


Return to the previous song in the playlist


Sets the volume ('1.0' is 100%) and/or returns the current volume.


Turns shuffle on or off -- should set before adding the MP3s and this does require a patch to your AlsaPlayer as described below.


Returns the current album title (only if ID3 tags are set to be read in your alsaplayer config and the MP3 has ID3 tags).


Returns the current song title (if ID3 tags are set to be read in your alsaplayer config and the MP3 has ID3 tags) or the name of the current MP3.


Returns the current artist name (only if ID3 tags are set to be read in your alsaplayer config and the MP3 has ID3 tags).


Returns the filename of the song currently being played.


Returns number of songs in playlist.


Returns true if one or more commands are waiting to be executed OR if songs are waiting to be added to the playlist.


Adds arbitrary MP3s to this player


Removes arbitrary MP3s from this player


Removes all playlists and MP3s


Returns current playlist


Returns length current playlist


Shuts down the player (restart by calling start())


Restarts the player (I use this on my voice output channel... once I play MP3s on that output, until I restart alsaplayer aplay does not produce very good quality audio)


You can change the default binary location and options by copying the following lines into your mh.private.ini:

  alsaplayer_opts= -q --nosave -i daemon -P


Kirk Bauer



This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


Hey! The above document had some coding errors, which are explained below:

Around line 819:

=cut found outside a pod block. Skipping to next block.

Around line 861:

=cut found outside a pod block. Skipping to next block.