Audio-aKodePlayer

 view release on metacpan or  search on metacpan

lib/Audio/aKodePlayer.pm  view on Meta::CPAN

use Carp;

=head1 NAME

Audio::aKodePlayer - A simple Perl interface to the aKode audio library.

=head1 VERSION

Version 0.01

=cut

our $VERSION = '0.01';
require XSLoader;
XSLoader::load('Audio::aKodePlayer', $VERSION);

use constant {
  CLOSED  => 0,
  OPEN    => 2,
  LOADED  => 4,
  PLAYING => 8,
  PAUSED  => 12
};

sub isClosed {
  my $self = shift;
  return ($self->state == CLOSED) ? 1 : 0;
}

sub isOpen {
  my $self = shift;
  return ($self->state == OPEN)  ? 1 : 0;
}

sub isLoaded {
  my $self = shift;
  return ($self->state == LOADED)  ? 1 : 0;
}

sub isPlaying {
  my $self = shift;
  return ($self->state == PLAYING) ? 1 : 0;
}

sub isPaused {
  my $self = shift;
  return ($self->state == PAUSED) ? 1 : 0;
}

1;
__END__

=head1 DESCRIPTION

This module provides a simple interface to the aKode::Player class
from the C++ aKode library. aKode is a simple audio-decoding
frame-work that provides a uniform interface to decode the most common
audio-formats such as WAV, MP3, Ogg/Vorbis, Ogg/FLAC, etc.  It also
has a direct playback option for a number of audio-outputs, such as
OSS, Alsa, SunOS/Solaris audio, Jack, and Polyp (recommended for
network transparent audio).

=head1 SYNOPSIS

  use Audio::aKodePlayer;

  my $player = Audio::aKodePlayer->new();
  $player->open('auto'); # automatically selected output sink
  $player->load( 'my_audio.ogg' ); # any format supported by aKode
  $player->play();
  $player->seek(10*1000) if $player->seekable; # seek 10 seconds from the beginning
  while (!$player->eof) {
    print "Playback position: ".($player->position()/1000)." seconds of ".($player->length()/1000)."\n";
    sleep 1;
  }
    ...
  $player->pause();
  $player->resume();
  $player->setVolume(0.75);
  print "Current volume is at ".($player->volume()*100)."%\n";
    ...
  $player->wait;   # idle until the playback stops
  $player->stop;   # stop playback
  $player->unload; # release resources related to the media
  $player->close;  # release resources related to the the output sink


=head1 EXPORT

None.

=cut

=head1 FUNCTIONS

=over 4

=item new()

Create a new Audio::aKodePlayer object.

=item open(sinkname)

Opens a player that outputs to the sink sinkname (the sink 'auto' is
recommended, other options are 'alsa', 'jack', 'oss', 'polyp', 'sun',
and maybe other, depending on the aKode installation).

Returns false if the device cannot be opened.

=item close()

Closes the player and releases the output sink.

=item load(filename)

Loads the file from a given filename and prepares it for
playing. Returns false if the file cannot be loaded or decoded.

=item setDecoderPlugin(plugin_name)

Sets the decoder plugin to use. Default is auto-detect.



( run in 1.479 second using v1.01-cache-2.11-cpan-22024b96cdf )