manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

19.2.3 Playback

Bigloo supports various functions for playing music. These functions rely on two data structure: music players and music status. The first ones are used to control player back-ends. The second ones are used to get information about the music being played. The following example shows how a simple music player using either MPlayer, MPG123, or MPC can be programmed with Bigloo.

(module musicplay
   (library multimedia)
   (main main))

(define (main args)
   (let ((files '())
	 (backend 'mplayer)
	 (command #f))
      (args-parse (cdr args)
	 (("--mpg123" (help "Select the mpg123 back-end"))
	  (set! backend 'mpg123))
	 (("--mpc" (help "Select the mpc back-end"))
	  (set! backend 'mpc))
	 (("--mplayer" (help "Select the mplayer back-end"))
	  (set! backend 'mplayer))
	 (("--command" ?cmd (help "Set the command path"))
	  (set! command cmd))
	 (("--help" (help "This help"))
	  (print "usage: music [options] file ...")
	  (args-parse-usage #f)
	  (exit 0))
	 (else
	  (set! files (cons else files))))
      ;; create a music player
      (let ((player (case backend
		       ((mpg123)
			(if command
			    (instantiate::mpg123
			       (path command))
			    (instantiate::mpg123)))
		       ((mplayer)
			(if command
			    (instantiate::mplayer
			       (path command))
			    (instantiate::mplayer)))
		       ((mpc)
			(instantiate::mpc)))))
         ;; fill the music play list
	 (for-each (lambda (p) (music-playlist-add! player p)) (reverse files))
         ;; start playing
	 (music-play player)
         ;; run an event loop with call-backs associated to some events
	 (music-event-loop player
            :onstate (lambda (status)
                        (with-access::musicstatus status (state song volume)
                           (print "state   : " state)
                           (print "song    : " song)))
	    :onmeta (lambda (meta)
		       (print "meta    : " meta))
	    :onvolume (lambda (volume)
		       (print "volume  : " volume))))))
Bigloo Multimedia abstract class: music
(abstract-class music
   (frequency::long (default 2000000))

This abstract class is the root class of all music players.

Bigloo Multimedia class: musicproc::music
(class musicproc::music
   (charset::symbol (default 'ISO-LATIN-1)))

This class is used to reify player that are run in an external process.

Bigloo Multimedia class: mplayer::musicproc
(class mplayer::musicproc
   (path::bstring read-only (default "mplayer"))
   (args::pair-nil read-only (default '("-vo" "null" "-quiet" "-slave" "-idle")))
   (ao::obj read-only (default #unspecified))
   (ac::obj read-only (default #unspecified)))

A player based on the external software MPlayer. Creating such a player spawns in background a MPlayer process.

Bigloo Multimedia class: mpg123::musicproc
(class mpg123::musicproc
   (path::bstring read-only (default "mpg123"))
   (args::pair-nil read-only (default '("--remote"))))

A player based on the external software mpg123.

Bigloo Multimedia class: mpc::music
(class mpc::music
   (hello read-only (default #f))
   (host read-only (default "localhost"))
   (port read-only (default 6600))
   (timeout read-only (default 10008993))
   (prefix (default #f)))

A MPC client.

  • hello: an optional string written when the connection is establish with the MPD server.
  • prefix: an optional path prefix to be removed from music playlist. This is needed because MPD can only play music files registered in is private database. The file names used by MPD are relative a root directory used to fill the database. The prefix field allows programmer to write portable code that manages play list file names independently of the player selected.
Bigloo Multimedia class: musicstatus
(class musicstatus
   (state::symbol (default 'stop))
   (volume::obj (default -1))
   (repeat::bool (default #f))
   (random::bool (default #f))
   (playlistid::int (default -1))
   (playlistlength::int (default 0))
   (xfade::int (default 0))
   (song::int (default 0))
   (songid::int (default 0))
   (songpos (default 0))
   (songlength::int (default 0))
   (bitrate::int (default 0))
   (khz::int (default 0))
   (err::obj (default #f)))

The instances of the class musicstatus denote that state of a player.

Bigloo Multimedia procedure: music-close music
Bigloo Multimedia procedure: music-reset! music
Bigloo Multimedia procedure: music-closed? music

Closes, resets, and tests the state of a music player.

Bigloo Multimedia procedure: music-playlist-get music
Bigloo Multimedia procedure: music-playlist-add! music song
Bigloo Multimedia procedure: music-playlist-delete! music int
Bigloo Multimedia procedure: music-playlist-clear! music

These functions controls the playlist used by a player.

Note: The song argument is an UTF8 encoded string (see Section Unicode (UCS-2) Strings) whatever the local file system encoding is. The function music-playlist-get returns a list of UTF8 encoded names.

  • music-playlist-get: returns the list of songs (UTF8 names) of the current playlist.
  • music-playlist-add!: adds an extra song (UTF8 name) at the end of the playlist.
  • music-delete!: removes the song number int from the playlist.
  • music-clear!: erases the whole playlist.
Bigloo Multimedia procedure: music-play music [song]
Bigloo Multimedia procedure: music-seek music time [song]
Bigloo Multimedia procedure: music-stop music
Bigloo Multimedia procedure: music-pause music
Bigloo Multimedia procedure: music-next music
Bigloo Multimedia procedure: music-prev music

These functions changes the state of the music player. The function music-seek seeks the playback position to the position time, which is an integer denoting a number of seconds.

Bigloo Multimedia procedure: music-crossfade music int
Bigloo Multimedia procedure: music-random-set! music bool
Bigloo Multimedia procedure: music-repeat-set! music bool

These functions controls how songs playback should follow each other.

Bigloo Multimedia procedure: music-volume-get music
Bigloo Multimedia procedure: music-volume-set! music vol

Get and set the audio volume of a player. Some player use the native mixer supported by the operating system some others use a software mixer unrelated to the hardware.

Bigloo Multimedia procedure: music-status music
Bigloo Multimedia procedure: music-update-status! music status

The function music-status returns an instance of the musicstatus class which denotes the state of the player. The function music-update-status! updates this status.

Bigloo Multimedia procedure: music-song music
Bigloo Multimedia procedure: music-songpos music

These two functions return the number of the song being played and the position in the song. These functions are somehow redundant with the function music-status because the status also contains information about the playback song and playback position. However, for some players getting the music song and the playback position is cheaper than getting the whole player status.

Bigloo Multimedia procedure: music-meta music

Returns the metadata the current song.

Bigloo Multimedia procedure: music-reset-error! music

Reset the previous errors detected by a player.

Bigloo Multimedia procedure: music-event-loop music [:onstate] [:onmeta] [:onerror] [:onvolume]

The function music-event-loop enable event notifications when the state of a player changes. The keyword arguments are:

  • :onstate, a function of one parameter. When the player state changes, this function is called with an instance of musicstatus as first actual parameter.
  • :onmeta, a function of two parameters. This function is called when a metadata is detected in the music currently played.
  • :onerror, a function of one parameter, invoked when an error is detected.
  • :onvolume, a function of one parameter, invoked when the volume changes.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on October 23, 2011 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.