Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

SDL::Mixer for Ubuntu 19.04

by Dirk80 (Pilgrim)
on Nov 03, 2019 at 15:12 UTC ( [id://11108274]=perlquestion: print w/replies, xml ) Need Help??

Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:

I have an old script which is using the SDL::Mixer. But it is not running anymore. Installing SDL::Mixer via cpan failed for me. So I installed it via sudo apt-get install libsdl-perl.

I tried to run the following code:

#!/usr/bin/perl use strict; use warnings; use SDL::Mixer; my $mixer = SDL::Mixer->new( -frequency => 22050, -channels => 2, -size => 1024);

But I get the following error message:

Can't locate object method "new" via package "SDL::Mixer" at test.pl l +ine 8.

I have no idea what to do. Is SDL::Mixer not correctly installed? What do you recommend? Thank you very much!

Some more information: The following code tells me that I have version 1.2.12 installed.

use SDL::Mixer; use SDL::Version; my $version = SDL::Mixer::linked_version(); printf("%d.%d.%d\n", $version->major, $version->minor, $version->patch +);
The code in my script which I wrote in 2013 to play a wav-file looks as follows:
use SDL::Mixer; use SDL::Music; playMusicFile("test.wav"); BEGIN { my $music; my $mixer = SDL::Mixer->new( -frequency => 22050, -channels => 2, -size => 1024); sub playMusicFile { my $music_file = $_[0]; $music = new SDL::Music $music_file; $mixer->music_volume(40); $mixer->play_music($music, 0); } }

But as told before it is not working anymore.

Replies are listed 'Best First'.
Re: SDL::Mixer for Ubuntu 19.04
by hippo (Bishop) on Nov 03, 2019 at 16:23 UTC
    Can't locate object method "new" via package "SDL::Mixer" at test.pl line 8.

    The documentation for SDL::Mixer does not list "new" as a method so the error report is likely correct. Perhaps the API has changed substantially since you last installed it? It does not appear to have an object orientated interface at all, AFAICS.

      Thanks!! You are right. The API changed completely. I now changed the code as follows, and it works.:

      use SDL; use SDL::Mixer; use SDL::Mixer::Music; printf("Error initializing SDL_mixer: %s\n", SDL::get_error()) unless +SDL::Mixer::open_audio(22050, AUDIO_S16, 2, 1024) == 0; playMusicFile("test.wav"); sub playMusicFile { my $music_file = $_[0]; my $music = SDL::Mixer::Music::load_MUS( $music_file ); SDL::Mixer::Music::volume_music( 40 ); my $play_music = SDL::Mixer::Music::play_music( $music, 1 ); print $play_music; SDL::delay(10000); # fix delay, better would be a solution to wait + until song is finished, I have to find out this later }
Re: SDL::Mixer for Ubuntu 19.04
by 1nickt (Canon) on Nov 03, 2019 at 15:51 UTC

    Hi,

    "So I installed it via sudo apt-get install libsdl-perl"

    It looks like you may have installed the module into the library space for a different perl than you are using in your script (although your demo code showing how you got the version does not show the perl used). Installing via apt-get will put the modules in the right place for the system perl, which you may not be (and are recommended not to be) using for your development work. Check your @INC.

    Hope this helps!


    The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11108274]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found