I just tried the example code of the SDL Manual where you play some music.
By the SDL manual, I refer to the one that is hidden at the bottom of the
sdl.perl.org page, so that you really have to search for it in order to find
it - and even then you have to get along with an ugly github interface.
The good news is, that it worked perfectly here on Win 7 x64. Thank you!
The bad news is, that I don't have ogg or wav files, but mp3 files. And I
have them in a database (please don't ask why and please don't propose to
store them as files).
So, in general: Is there a way to play mp3 files? And in particular: is there a way to play mp3 files that are in a variable?
Or do I have to work with temporary files?
Here is what I got so far:
[code]
#!perl
use strict;
use warnings;
use SDL;
use Carp;
use SDL::Audio;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
SDL::init(SDL_INIT_AUDIO);
However, this code dies with an error: "Use of inherited AUTOLOAD for
non-method SDL::Mixer::Samples::load_MUS() is deprecated at
yadayada\play_sdl.pl line 20.".
The above code works fine when using an ogg file (using load_MUS()) or an
wav file (load_WAV()).
> I just tried the example code of the SDL Manual where you play some music.
> By the SDL manual, I refer to the one that is hidden at the bottom of the
> sdl.perl.org page, so that you really have to search for it in order to find
> it - and even then you have to get along with an ugly github interface.
There's a new project website under way, but we're missing people to
work in it. Please join #sdl in irc.perl.org if you want to help us
get it right :)
> So, in general: Is there a way to play mp3 files?
Yup.
If your libsdl was compiled with mp3 support, all you have to do
(iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio)
flags when you call SDL::Mixer::init():
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
then use load_MUS() and play_music() from SDL::Mixer::Music to play
mp3 files as background music, or load_WAV() from SDL::Mixer::Samples
to play mp3 effects (yes, the function is named load_WAV() but plays
different formats too if they're available).
The documentation in SDL::Mixer, SDL::Mixer::Music and
SDL::Mixer::Samples should be helpful, as some of the test files
(t/mixer_music.t comes to mind).
> And in particular: is there a way to play mp3 files that are in a variable?
> Or do I have to work with temporary files?
Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the
right thing. You'll have to test it though.
thank you for the quick response. It helped.
I had a look into mixer_samples.t and line 106 states, that quick_load_WAV
is not (yet? Who do I have to bribe with what to get it?) implemented.
Here is a working piece of code using temporary files. Of course, you need a
database containing audio files.
Best regards,
Alex
[code]
#!perl
use strict;
use warnings;
use utf8;
use DBI;
use SQL::Abstract::Limit;
use File::Temp;
use SDL;
use SDL::Audio;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
SDL::init(SDL_INIT_AUDIO);
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
sub get_audio_buffer {
my $sql = SQL::Abstract::Limit->new( limit_dialect => 'LimitXY' );;
my $table = 'audio_files';
my @fields = (qw/audio/);
my %where = (
id => 2,
);
my @order = ();
my $limit = 1;
my $offset = 0;
my ( $stmt, @bind ) = $sql->select( $table, \@fields, \%where, \@order,
$limit, $offset );
my $database = 'database_name';
my $db_host = 'your_host';
my $db_port = '3306';
my $dsn = "DBI:mysql:database=$database;host=$db_host;port=$db_port";
my $username = 'username';
my $password = 'password';
my $dbh = DBI->connect($dsn, $username, $password) or die('Cannot
connect to DB: ' . DBI->errstr());
my $sth = $dbh->prepare( $stmt );
$sth->execute( @bind );
my ($buffer) = $sth->fetchrow_array();
return $buffer;
} # /get_audio_buffer
[/code]
-----Ursprüngliche Nachricht-----
Von: breno [mailto:oainikus...@gmail.com] Gesendet: Dienstag, 29. November 2011 06:34
An: Alexander Becker
Cc: sdl-de...@perl.org
Betreff: Re: How to play an mp3 file from a database
On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
> Dear all!
Hi there!
> I just tried the example code of the SDL Manual where you play some music.
> By the SDL manual, I refer to the one that is hidden at the bottom of > the sdl.perl.org page, so that you really have to search for it in > order to find it - and even then you have to get along with an ugly github
interface.
There's a new project website under way, but we're missing people to work in
it. Please join #sdl in irc.perl.org if you want to help us get it right :)
> So, in general: Is there a way to play mp3 files?
Yup.
If your libsdl was compiled with mp3 support, all you have to do
(iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags
when you call SDL::Mixer::init():
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
then use load_MUS() and play_music() from SDL::Mixer::Music to play
mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to
play mp3 effects (yes, the function is named load_WAV() but plays different
formats too if they're available).
The documentation in SDL::Mixer, SDL::Mixer::Music and SDL::Mixer::Samples
should be helpful, as some of the test files (t/mixer_music.t comes to
mind).
> And in particular: is there a way to play mp3 files that are in a
variable?
> Or do I have to work with temporary files?
Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the right
thing. You'll have to test it though.
Cheers,
breno
-----
eMail ist virenfrei.
Von AVG überprüft - www.avg.de Version: 10.0.1411 / Virendatenbank: 2092/4046 - Ausgabedatum: 29.11.2011
> thank you for the quick response. It helped.
> I had a look into mixer_samples.t and line 106 states, that quick_load_WAV
> is not (yet? Who do I have to bribe with what to get it?) implemented.
> Here is a working piece of code using temporary files. Of course, you need a
> database containing audio files.
> Best regards,
> Alex
> [code]
> #!perl
> use strict;
> use warnings;
> use utf8;
> use DBI;
> use SQL::Abstract::Limit;
> use File::Temp;
> use SDL;
> use SDL::Audio;
> use SDL::Mixer;
> use SDL::Mixer::Samples;
> use SDL::Mixer::Channels;
> use SDL::Mixer::Music;
> SDL::init(SDL_INIT_AUDIO);
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> -----Ursprüngliche Nachricht-----
> Von: breno [mailto:oainikus...@gmail.com] > Gesendet: Dienstag, 29. November 2011 06:34
> An: Alexander Becker
> Cc: sdl-de...@perl.org
> Betreff: Re: How to play an mp3 file from a database
> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
>> Dear all!
> Hi there!
>> I just tried the example code of the SDL Manual where you play some music.
>> By the SDL manual, I refer to the one that is hidden at the bottom of >> the sdl.perl.org page, so that you really have to search for it in >> order to find it - and even then you have to get along with an ugly github
> interface.
> There's a new project website under way, but we're missing people to work in
> it. Please join #sdl in irc.perl.org if you want to help us get it right :)
>> So, in general: Is there a way to play mp3 files?
> Yup.
> If your libsdl was compiled with mp3 support, all you have to do
> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags
> when you call SDL::Mixer::init():
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> then use load_MUS() and play_music() from SDL::Mixer::Music to play
> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to
> play mp3 effects (yes, the function is named load_WAV() but plays different
> formats too if they're available).
> The documentation in SDL::Mixer, SDL::Mixer::Music and SDL::Mixer::Samples
> should be helpful, as some of the test files (t/mixer_music.t comes to
> mind).
>> And in particular: is there a way to play mp3 files that are in a
> variable?
>> Or do I have to work with temporary files?
> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the right
> thing. You'll have to test it though.
The example code in your link gives me version 1.2.11 on Win 7 x64 with
strawberry perl 5.12.2 built for MSWin32-x64-multi-thread.
HTH, Alex
[code]
use SDL::Mixer;
use SDL::Version;
my $version = SDL::Mixer::linked_version();
printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); #
prints "1.2.11" for me
[/code]
-----Ursprüngliche Nachricht-----
Von: Tobias Leich [mailto:em...@froggs.de] Gesendet: Mittwoch, 30. November 2011 13:18
An: Alexander Becker
Cc: 'breno'; sdl-de...@perl.org
Betreff: Re: How to play an mp3 file from a database
Hi, can you please check what version of libSDL_mixer do you have installed?
> thank you for the quick response. It helped.
> I had a look into mixer_samples.t and line 106 states, that > quick_load_WAV is not (yet? Who do I have to bribe with what to get it?)
implemented.
> Here is a working piece of code using temporary files. Of course, you > need a database containing audio files.
> Best regards,
> Alex
> [code]
> #!perl
> use strict;
> use warnings;
> use utf8;
> use DBI;
> use SQL::Abstract::Limit;
> use File::Temp;
> use SDL;
> use SDL::Audio;
> use SDL::Mixer;
> use SDL::Mixer::Samples;
> use SDL::Mixer::Channels;
> use SDL::Mixer::Music;
> SDL::init(SDL_INIT_AUDIO);
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> -----Ursprüngliche Nachricht-----
> Von: breno [mailto:oainikus...@gmail.com]
> Gesendet: Dienstag, 29. November 2011 06:34
> An: Alexander Becker
> Cc: sdl-de...@perl.org
> Betreff: Re: How to play an mp3 file from a database
> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
>> Dear all!
> Hi there!
>> I just tried the example code of the SDL Manual where you play some
music.
>> By the SDL manual, I refer to the one that is hidden at the bottom of >> the sdl.perl.org page, so that you really have to search for it in >> order to find it - and even then you have to get along with an ugly >> github
> interface.
> There's a new project website under way, but we're missing people to > work in it. Please join #sdl in irc.perl.org if you want to help us > get it right :)
>> So, in general: Is there a way to play mp3 files?
> Yup.
> If your libsdl was compiled with mp3 support, all you have to do
> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) > flags when you call SDL::Mixer::init():
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> then use load_MUS() and play_music() from SDL::Mixer::Music to play
> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples > to play mp3 effects (yes, the function is named load_WAV() but plays > different formats too if they're available).
> The documentation in SDL::Mixer, SDL::Mixer::Music and > SDL::Mixer::Samples should be helpful, as some of the test files > (t/mixer_music.t comes to mind).
>> And in particular: is there a way to play mp3 files that are in a
> variable?
>> Or do I have to work with temporary files?
> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the > right thing. You'll have to test it though.
> The example code in your link gives me version 1.2.11 on Win 7 x64 with
> strawberry perl 5.12.2 built for MSWin32-x64-multi-thread.
> HTH, > Alex
> [code]
> use SDL::Mixer;
> use SDL::Version;
> my $version = SDL::Mixer::linked_version();
> printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); #
> prints "1.2.11" for me
> [/code]
> -----Ursprüngliche Nachricht-----
> Von: Tobias Leich [mailto:em...@froggs.de] > Gesendet: Mittwoch, 30. November 2011 13:18
> An: Alexander Becker
> Cc: 'breno'; sdl-de...@perl.org
> Betreff: Re: How to play an mp3 file from a database
> Hi, can you please check what version of libSDL_mixer do you have installed?
> In case you have 1.2.7 or better we can add support for RWOps objects.
> So you dont need temp files.
> Cheers, FROGGS
> Am 29.11.2011 20:37, schrieb Alexander Becker:
>> Hi breno,
>> thank you for the quick response. It helped.
>> I had a look into mixer_samples.t and line 106 states, that >> quick_load_WAV is not (yet? Who do I have to bribe with what to get it?)
> implemented.
>> Here is a working piece of code using temporary files. Of course, you >> need a database containing audio files.
>> Best regards,
>> Alex
>> [code]
>> #!perl
>> use strict;
>> use warnings;
>> use utf8;
>> use DBI;
>> use SQL::Abstract::Limit;
>> use File::Temp;
>> use SDL;
>> use SDL::Audio;
>> use SDL::Mixer;
>> use SDL::Mixer::Samples;
>> use SDL::Mixer::Channels;
>> use SDL::Mixer::Music;
>> SDL::init(SDL_INIT_AUDIO);
>> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
>> -----Ursprüngliche Nachricht-----
>> Von: breno [mailto:oainikus...@gmail.com]
>> Gesendet: Dienstag, 29. November 2011 06:34
>> An: Alexander Becker
>> Cc: sdl-de...@perl.org
>> Betreff: Re: How to play an mp3 file from a database
>> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
>>> Dear all!
>> Hi there!
>>> I just tried the example code of the SDL Manual where you play some
> music.
>>> By the SDL manual, I refer to the one that is hidden at the bottom of >>> the sdl.perl.org page, so that you really have to search for it in >>> order to find it - and even then you have to get along with an ugly >>> github
>> interface.
>> There's a new project website under way, but we're missing people to >> work in it. Please join #sdl in irc.perl.org if you want to help us >> get it right :)
>>> So, in general: Is there a way to play mp3 files?
>> Yup.
>> If your libsdl was compiled with mp3 support, all you have to do
>> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) >> flags when you call SDL::Mixer::init():
>> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
>> then use load_MUS() and play_music() from SDL::Mixer::Music to play
>> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples >> to play mp3 effects (yes, the function is named load_WAV() but plays >> different formats too if they're available).
>> The documentation in SDL::Mixer, SDL::Mixer::Music and >> SDL::Mixer::Samples should be helpful, as some of the test files >> (t/mixer_music.t comes to mind).
>>> And in particular: is there a way to play mp3 files that are in a
>> variable?
>>> Or do I have to work with temporary files?
>> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the >> right thing. You'll have to test it though.
> So I will add RWOps support today, I'll drop you a note when its done.
> Cheers, FROGGS
> Am 30.11.2011 23:09, schrieb Alexander Becker:
>> Hi!
>> The example code in your link gives me version 1.2.11 on Win 7 x64 with
>> strawberry perl 5.12.2 built for MSWin32-x64-multi-thread.
>> HTH,
>> Alex
>> [code]
>> use SDL::Mixer;
>> use SDL::Version;
>> my $version = SDL::Mixer::linked_version();
>> printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); #
>> prints "1.2.11" for me
>> [/code]
>> -----Ursprüngliche Nachricht-----
>> Von: Tobias Leich [mailto:em...@froggs.de]
>> Gesendet: Mittwoch, 30. November 2011 13:18
>> An: Alexander Becker
>> Cc: 'breno'; sdl-de...@perl.org
>> Betreff: Re: How to play an mp3 file from a database
>> Hi, can you please check what version of libSDL_mixer do you have installed?
>> In case you have 1.2.7 or better we can add support for RWOps objects.
>> So you dont need temp files.
>> Cheers, FROGGS
>> Am 29.11.2011 20:37, schrieb Alexander Becker:
>>> Hi breno,
>>> thank you for the quick response. It helped.
>>> I had a look into mixer_samples.t and line 106 states, that
>>> quick_load_WAV is not (yet? Who do I have to bribe with what to get it?)
>> implemented.
>>> Here is a working piece of code using temporary files. Of course, you
>>> need a database containing audio files.
>>> Best regards,
>>> Alex
>>> [code]
>>> #!perl
>>> use strict;
>>> use warnings;
>>> use utf8;
>>> use DBI;
>>> use SQL::Abstract::Limit;
>>> use File::Temp;
>>> use SDL;
>>> use SDL::Audio;
>>> use SDL::Mixer;
>>> use SDL::Mixer::Samples;
>>> use SDL::Mixer::Channels;
>>> use SDL::Mixer::Music;
>>> SDL::init(SDL_INIT_AUDIO);
>>> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
>>> -----Ursprüngliche Nachricht-----
>>> Von: breno [mailto:oainikus...@gmail.com]
>>> Gesendet: Dienstag, 29. November 2011 06:34
>>> An: Alexander Becker
>>> Cc: sdl-de...@perl.org
>>> Betreff: Re: How to play an mp3 file from a database
>>> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
>>>> Dear all!
>>> Hi there!
>>>> I just tried the example code of the SDL Manual where you play some
>> music.
>>>> By the SDL manual, I refer to the one that is hidden at the bottom of
>>>> the sdl.perl.org page, so that you really have to search for it in
>>>> order to find it - and even then you have to get along with an ugly
>>>> github
>>> interface.
>>> There's a new project website under way, but we're missing people to
>>> work in it. Please join #sdl in irc.perl.org if you want to help us
>>> get it right :)
>>>> So, in general: Is there a way to play mp3 files?
>>> Yup.
>>> If your libsdl was compiled with mp3 support, all you have to do
>>> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio)
>>> flags when you call SDL::Mixer::init():
>>> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
>>> then use load_MUS() and play_music() from SDL::Mixer::Music to play
>>> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples
>>> to play mp3 effects (yes, the function is named load_WAV() but plays
>>> different formats too if they're available).
>>> The documentation in SDL::Mixer, SDL::Mixer::Music and
>>> SDL::Mixer::Samples should be helpful, as some of the test files
>>> (t/mixer_music.t comes to mind).
>>>> And in particular: is there a way to play mp3 files that are in a
>>> variable?
>>>> Or do I have to work with temporary files?
>>> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the
>>> right thing. You'll have to test it though.
> Can't find dist packages without a MANIFEST file
> Run 'Build manifest' to generate one
> WARNING: Possible missing or corrupt 'MANIFEST' file.
> Nothing to enter for 'provides' field in metafile.
> Created MYMETA.yml and MYMETA.json
> Creating new 'Build' script for 'SDL' version '2.535_01'
> C:\zwischen\cpan\PerlGameDev-SDL-44c341f>
> [/snip]
> Will this be in an official release of SDL? Because this would be a
> really nice feature, that could be advertised, e.g. via blogs entries
> etc.. I could write a german one.
> Best regards & thanks a lot,
> Alex
> *Von:*Tobias Leich [mailto:em...@froggs.de]
> *Gesendet:* Donnerstag, 1. Dezember 2011 18:37
> *An:* Alexander Becker
> *Betreff:* Re: How to play an mp3 file from a database
> Hi Alex,
> You can checkout the c-sdl-rwops branch at github or download the
> zipfile if you are not experienced with git by using this link:
> use SDL;
> use SDL::Mixer;
> use SDL::Mixer::Music;
> use SDL::RWOps;
> [...]
> my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music );
> my $music = SDL::Mixer::Music::load_MUS( $rwops );
> Cheers
> Am 30.11.2011 23:09, schrieb Alexander Becker:
> Hi!
> The example code in your link gives me version 1.2.11 on Win 7 x64 with
> strawberry perl 5.12.2 built for MSWin32-x64-multi-thread.
> HTH, > Alex
> [code]
> use SDL::Mixer;
> use SDL::Version;
> my $version = SDL::Mixer::linked_version();
> printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); #
> prints "1.2.11" for me
> [/code]
> -----Ursprüngliche Nachricht-----
> Von: Tobias Leich [mailto:em...@froggs.de] > Gesendet: Mittwoch, 30. November 2011 13:18
> An: Alexander Becker
> Cc: 'breno'; sdl-de...@perl.org <mailto:sdl-de...@perl.org>
> Betreff: Re: How to play an mp3 file from a database
> Hi, can you please check what version of libSDL_mixer do you have installed?
[Alien::SDL] Testing header(s): execinfo.h, signal.h NOK: (error:
execinfo.h: No
such file or directory)
Can't find dist packages without a MANIFEST file
Run 'Build manifest' to generate one
WARNING: Possible missing or corrupt 'MANIFEST' file.
Nothing to enter for 'provides' field in metafile.
Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'SDL' version '2.535_01'
C:\zwischen\cpan\PerlGameDev-SDL-44c341f>
[/snip]
Will this be in an official release of SDL? Because this would be a really
nice feature, that could be advertised, e.g. via blogs entries etc.. I could
write a german one.
Best regards & thanks a lot,
Alex
Von: Tobias Leich [mailto:em...@froggs.de] Gesendet: Donnerstag, 1. Dezember 2011 18:37
An: Alexander Becker
Betreff: Re: How to play an mp3 file from a database
Hi Alex,
You can checkout the c-sdl-rwops branch at github or download the zipfile if
you are not experienced with git by using this link:
use SDL;
use SDL::Mixer;
use SDL::Mixer::Music;
use SDL::RWOps;
[...]
my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music );
my $music = SDL::Mixer::Music::load_MUS( $rwops );
Cheers
Am 30.11.2011 23:09, schrieb Alexander Becker:
Hi!
The example code in your link gives me version 1.2.11 on Win 7 x64 with
strawberry perl 5.12.2 built for MSWin32-x64-multi-thread.
HTH, Alex
[code]
use SDL::Mixer;
use SDL::Version;
my $version = SDL::Mixer::linked_version();
printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch); #
prints "1.2.11" for me
[/code]
-----Ursprüngliche Nachricht-----
Von: Tobias Leich [mailto:em...@froggs.de] Gesendet: Mittwoch, 30. November 2011 13:18
An: Alexander Becker
Cc: 'breno'; sdl-de...@perl.org
Betreff: Re: How to play an mp3 file from a database
Hi, can you please check what version of libSDL_mixer do you have installed?
In case you have 1.2.7 or better we can add support for RWOps objects.
So you dont need temp files.
Cheers, FROGGS
Am 29.11.2011 20:37, schrieb Alexander Becker:
Hi breno,
thank you for the quick response. It helped.
I had a look into mixer_samples.t and line 106 states, that quick_load_WAV is not (yet? Who do I have to bribe with what to get it?)
implemented.
Here is a working piece of code using temporary files. Of course, you need a database containing audio files.
Best regards,
Alex
[code]
#!perl
use strict;
use warnings;
use utf8;
use DBI;
use SQL::Abstract::Limit;
use File::Temp;
use SDL;
use SDL::Audio;
use SDL::Mixer;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
use SDL::Mixer::Music;
SDL::init(SDL_INIT_AUDIO);
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
sub get_audio_buffer {
my $sql = SQL::Abstract::Limit->new( limit_dialect => 'LimitXY' );;
my $table = 'audio_files';
my @fields = (qw/audio/);
my %where = (
id => 2,
);
my @order = ();
my $limit = 1;
my $offset = 0;
my ( $stmt, @bind ) = $sql->select( $table, \@fields, \%where, \@order, $limit, $offset );
my $database = 'database_name';
my $db_host = 'your_host';
my $db_port = '3306';
my $dsn = "DBI:mysql:database=$database;host=$db_host;port=$db_port";
my $username = 'username';
my $password = 'password';
my $dbh = DBI->connect($dsn, $username, $password) or die('Cannot connect to DB: ' . DBI->errstr());
my $sth = $dbh->prepare( $stmt );
$sth->execute( @bind );
my ($buffer) = $sth->fetchrow_array();
return $buffer;
} # /get_audio_buffer
[/code]
-----Ursprüngliche Nachricht-----
Von: breno [mailto:oainikus...@gmail.com]
Gesendet: Dienstag, 29. November 2011 06:34
An: Alexander Becker
Cc: sdl-de...@perl.org
Betreff: Re: How to play an mp3 file from a database
On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker < > wrote:
Dear all!
Hi there!
I just tried the example code of the SDL Manual where you play some
music.
By the SDL manual, I refer to the one that is hidden at the bottom of the sdl.perl.org page, so that you really have to search for it in order to find it - and even then you have to get along with an ugly github
interface.
There's a new project website under way, but we're missing people to work in it. Please join #sdl in irc.perl.org if you want to help us get it right :)
So, in general: Is there a way to play mp3 files?
Yup.
If your libsdl was compiled with mp3 support, all you have to do
(iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags when you call SDL::Mixer::init():
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
then use load_MUS() and play_music() from SDL::Mixer::Music to play
mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to play mp3 effects (yes, the function is named load_WAV() but plays different formats too if
...
Now I want to play a vocable audio file (that is of course, stored in a
database :)). I can't use SDL::Mixer::Music for that, because there is
already some background music playing. AFAIK I need to use
SDL::Mixer::Samples.
I tried it, but there occurred an error when using mp3 files: "Cannot load
music file [music/terminal.mp3]: Unrecognized sound file type at
play_effect.pl line 34"
Here is the script:
[code]
#!perl
use strict;
use warnings;
use utf8;
use SDL;
use SDL::Event;
use SDL::Events;
use SDLx::App;
use SDLx::Controller;
use SDL::Mixer;
use SDL::Mixer::Music;
use SDL::RWOps;
use SDL::Mixer::Samples;
use SDL::Mixer::Channels;
SDL::init(SDL_INIT_AUDIO);
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
my $app = SDLx::App->new(
title => 'play mp3 effect',
exit_on_quit => 1,
);
There also occurred some other errors using .wav files:
- Cannot load music file [music/br_crossing_bell_dop.r.wav]: Complex WAVE
files not supported at play_effect.pl line 34
- Cannot load music file [music/Windows Logon Sound.wav]: MPEG Layer 3 data
not supported play_effect.pl line 34
But, I only want to play mp3 files.
Maybe you can hint me at the solution for this problem? How can I play an
mp3 file once, e.g. on a button click event?
Best regards,
Alex
-----Ursprüngliche Nachricht-----
Von: breno [mailto:oainikus...@gmail.com] Gesendet: Dienstag, 29. November 2011 06:34
An: Alexander Becker
Cc: sdl-de...@perl.org
Betreff: Re: How to play an mp3 file from a database
On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker <AlexanderBec...@gmx.net>
wrote:
> Dear all!
Hi there!
> I just tried the example code of the SDL Manual where you play some music.
> By the SDL manual, I refer to the one that is hidden at the bottom of > the sdl.perl.org page, so that you really have to search for it in > order to find it - and even then you have to get along with an ugly github
interface.
There's a new project website under way, but we're missing people to work in
it. Please join #sdl in irc.perl.org if you want to help us get it right :)
> So, in general: Is there a way to play mp3 files?
Yup.
If your libsdl was compiled with mp3 support, all you have to do
(iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags
when you call SDL::Mixer::init():
SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
then use load_MUS() and play_music() from SDL::Mixer::Music to play
mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to
play mp3 effects (yes, the function is named load_WAV() but plays different
formats too if they're available).
The documentation in SDL::Mixer, SDL::Mixer::Music and SDL::Mixer::Samples
should be helpful, as some of the test files (t/mixer_music.t comes to
mind).
> And in particular: is there a way to play mp3 files that are in a
variable?
> Or do I have to work with temporary files?
Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the right
thing. You'll have to test it though.
> Now I want to play a vocable audio file (that is of course, stored in a
> database :)). I can't use SDL::Mixer::Music for that, because there is
> already some background music playing. AFAIK I need to use
> SDL::Mixer::Samples.
> I tried it, but there occurred an error when using mp3 files: "Cannot load
> music file [music/terminal.mp3]: Unrecognized sound file type at
> play_effect.pl line 34"
> Here is the script:
> [code]
> #!perl
> use strict;
> use warnings;
> use utf8;
> use SDL;
> use SDL::Event;
> use SDL::Events;
> use SDLx::App;
> use SDLx::Controller;
> use SDL::Mixer;
> use SDL::Mixer::Music;
> use SDL::RWOps;
> use SDL::Mixer::Samples;
> use SDL::Mixer::Channels;
> SDL::init(SDL_INIT_AUDIO);
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> my $app = SDLx::App->new(
> title => 'play mp3 effect',
> exit_on_quit => 1,
> );
> There also occurred some other errors using .wav files:
> - Cannot load music file [music/br_crossing_bell_dop.r.wav]: Complex WAVE
> files not supported at play_effect.pl line 34
> - Cannot load music file [music/Windows Logon Sound.wav]: MPEG Layer 3 data
> not supported play_effect.pl line 34
> But, I only want to play mp3 files.
> Maybe you can hint me at the solution for this problem? How can I play an
> mp3 file once, e.g. on a button click event?
> Best regards,
> Alex
> -----Ursprüngliche Nachricht-----
> Von: breno [mailto:oainikus...@gmail.com] > Gesendet: Dienstag, 29. November 2011 06:34
> An: Alexander Becker
> Cc: sdl-de...@perl.org
> Betreff: Re: How to play an mp3 file from a database
> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker <AlexanderBec...@gmx.net>
> wrote:
>> Dear all!
> Hi there!
>> I just tried the example code of the SDL Manual where you play some music.
>> By the SDL manual, I refer to the one that is hidden at the bottom of >> the sdl.perl.org page, so that you really have to search for it in >> order to find it - and even then you have to get along with an ugly github
> interface.
> There's a new project website under way, but we're missing people to work in
> it. Please join #sdl in irc.perl.org if you want to help us get it right :)
>> So, in general: Is there a way to play mp3 files?
> Yup.
> If your libsdl was compiled with mp3 support, all you have to do
> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) flags
> when you call SDL::Mixer::init():
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> then use load_MUS() and play_music() from SDL::Mixer::Music to play
> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples to
> play mp3 effects (yes, the function is named load_WAV() but plays different
> formats too if they're available).
> The documentation in SDL::Mixer, SDL::Mixer::Music and SDL::Mixer::Samples
> should be helpful, as some of the test files (t/mixer_music.t comes to
> mind).
>> And in particular: is there a way to play mp3 files that are in a
> variable?
>> Or do I have to work with temporary files?
> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the right
> thing. You'll have to test it though.
Ok, now I don't get any error when playing mp3 files from the database, but
I don't get any sound either.
I updated Alien::SDL to the latest version, that worked.
However, SDL itself didn't pass the tests, it's the channels test that
fails. So I installed with force, but no change.
Is there anything in particular I could do to provide information about the
error that occurs with the cannels test? Any information you need to fix
this issue (in case it is one)?
Best regards,
Alex
[snip]
Test Summary Report
-------------------
t\core.t (Wstat: 0 Tests: 28 Failed: 0)
TODO passed: 21-22
t\core_video.t (Wstat: 0 Tests: 110 Failed: 0)
TODO passed: 57, 59
t\mixer_channels.t (Wstat: 65280 Tests: 35 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
Files=59, Tests=3942, 233 wallclock secs ( 0.94 usr + 0.23 sys = 1.17 CPU)
Result: FAIL
Failed 1/59 test programs. 0/3942 subtests failed.
(C:\strawberry\perl\bin\perl.exe ./Build test exited with 65280)
CPAN::Reporter: Test result is 'fail', One or more tests failed.
CPAN::Reporter: preparing a CPAN Testers report for SDL-2.536
CPAN::Reporter: this appears to be a duplicate report for the test phase:
FAIL SDL-2.536 MSWin32-x64-multi-thread 6.1
Test report will not be sent.
FROGGS/SDL-2.536.tar.gz
C:\strawberry\perl\bin\perl.exe ./Build test -- NOT OK
//hint// to see the cpan-testers results for installing this module, try:
reports FROGGS/SDL-2.536.tar.gz
Running Build install
make test had returned bad status, won't install without force
Failed during this command:
FROGGS/SDL-2.536.tar.gz : make_test NO
[/snip]
-----Ursprüngliche Nachricht-----
Von: Tobias Leich [mailto:em...@froggs.de] Gesendet: Sonntag, 22. April 2012 19:31
An: Alex
Betreff: Re: How to play an mp3 file from a database
Hi Alex,
At first, you are on windows and used the prebuklt libSDL binaries shipped
with Alien::SDL?
If yes, mp3 should be supported, but only files without VBR. So please try a
few mp3 files and maybe check how it is encoded.
Then, to play an mp3 file from a database, do somethind like:
use DBI;
use SDL;
use SDL::Mixer;
use SDL::Mixer::Channels;
use SDL::Mixer::Samples;
use SDL::RWOps;
> Now I want to play a vocable audio file (that is of course, stored in > a database :)). I can't use SDL::Mixer::Music for that, because there > is already some background music playing. AFAIK I need to use > SDL::Mixer::Samples.
> I tried it, but there occurred an error when using mp3 files: "Cannot > load music file [music/terminal.mp3]: Unrecognized sound file type at > play_effect.pl line 34"
> Here is the script:
> [code]
> #!perl
> use strict;
> use warnings;
> use utf8;
> use SDL;
> use SDL::Event;
> use SDL::Events;
> use SDLx::App;
> use SDLx::Controller;
> use SDL::Mixer;
> use SDL::Mixer::Music;
> use SDL::RWOps;
> use SDL::Mixer::Samples;
> use SDL::Mixer::Channels;
> SDL::init(SDL_INIT_AUDIO);
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> my $app = SDLx::App->new(
> title => 'play mp3 effect',
> exit_on_quit => 1,
> );
> There also occurred some other errors using .wav files:
> - Cannot load music file [music/br_crossing_bell_dop.r.wav]: Complex > WAVE files not supported at play_effect.pl line 34
> - Cannot load music file [music/Windows Logon Sound.wav]: MPEG Layer 3 > data not supported play_effect.pl line 34
> But, I only want to play mp3 files.
> Maybe you can hint me at the solution for this problem? How can I play > an
> mp3 file once, e.g. on a button click event?
> Best regards,
> Alex
> -----Ursprüngliche Nachricht-----
> Von: breno [mailto:oainikus...@gmail.com]
> Gesendet: Dienstag, 29. November 2011 06:34
> An: Alexander Becker
> Cc: sdl-de...@perl.org
> Betreff: Re: How to play an mp3 file from a database
> On Mon, Nov 28, 2011 at 8:13 PM, Alexander Becker > <AlexanderBec...@gmx.net>
> wrote:
>> Dear all!
> Hi there!
>> I just tried the example code of the SDL Manual where you play some
music.
>> By the SDL manual, I refer to the one that is hidden at the bottom of >> the sdl.perl.org page, so that you really have to search for it in >> order to find it - and even then you have to get along with an ugly >> github
> interface.
> There's a new project website under way, but we're missing people to > work in it. Please join #sdl in irc.perl.org if you want to help us > get it right :)
>> So, in general: Is there a way to play mp3 files?
> Yup.
> If your libsdl was compiled with mp3 support, all you have to do
> (iirc) is set the MIX_INIT_MP3 (for effects) and MUS_MP3 (for audio) > flags when you call SDL::Mixer::init():
> SDL::Mixer::init( MIX_INIT_MP3 | MUS_MP3 );
> then use load_MUS() and play_music() from SDL::Mixer::Music to play
> mp3 files as background music, or load_WAV() from SDL::Mixer::Samples > to play mp3 effects (yes, the function is named load_WAV() but plays > different formats too if they're available).
> The documentation in SDL::Mixer, SDL::Mixer::Music and > SDL::Mixer::Samples should be helpful, as some of the test files > (t/mixer_music.t comes to mind).
>> And in particular: is there a way to play mp3 files that are in a
> variable?
>> Or do I have to work with temporary files?
> Not sure. I *think* SDL::Mixer::quick_load_WAV( $buffer ) might do the > right thing. You'll have to test it though.
> Cheers,
> breno
-----
eMail ist virenfrei.
Von AVG überprüft - www.avg.de Version: 2012.0.1913 / Virendatenbank: 2411/4952 - Ausgabedatum: 22.04.2012