Dear all!

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);

unless( SDL::Mixer::open_audio( 44100, AUDIO_S16SYS, 2, 4096 ) == 0 )
{
        Carp::croak "Cannot open audio: ".SDL::get_error(); 
}

my $sound_file = 'data/ghostngoblins.mp3';
my $sample = SDL::Mixer::Samples::load_MUS($sound_file);

unless( $sample)
{
        Carp::croak "Cannot load file [$sound_file]: ".SDL::get_error(); 
}

my $playing_channel = SDL::Mixer::Channels::play_channel( -1, $sample, 0 );

sleep(60);

SDL::Mixer::Music::halt_music();
SDL::Mixer::close_audio;
exit(0);
[/code]

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()).

Please help :)

Best regards,
Alex

Reply via email to