From: Tobias Leich SDL::Mixer::Music -- SDL_Mixer music functions and bindings SDL::Mixer::Music - functions for music Mixer Same as SDL::Audio::mix() has to be implemented This sets up a custom music player function, so you can pass your own audio stream data into the SDL::Mixer.
+The function will be called with To stop the custom music player call Note: NEVER call Note: At program termination also call Example: This callback is called when music called by e.g. play_music or fade_in_music stops naturally. This happens when the music is over or is
+fading out. Note: If you play music via hook_music, this callback will never be called. Example: Returns the
NAME
CATEGORY
@@ -42,28 +38,10 @@
DESCRIPTION
-METHODS
PerlMixMusicHook
-mix_audio
-load_WAV
-load_MUS
my $music = SDL::Mixer::Music::load_MUS( $file );
@@ -72,20 +50,79 @@
load_MUS
loads a music file into a SDL::Music::MixMusic
structure. This can be passed to play_music.free_music
-hook_music
SDL::Mixer::Music::hook_music( $callback, $position );
+
+ or
+
+ SDL::Mixer::Music::hook_music( &callback, $position );
+
+
+position
passed into the first parameter when the callback
is called.
+The audio stream buffer has to be filled with length bytes of music (2nd parameter).
+The music player will then be called automatically when the mixer needs it. Music playing will start as soon as this is called.
+All the music playing and stopping functions have no effect on music after this. Pause and resume will work.
+Using a custom music player and the internal music player is not possible, the custom music player takes priority. hook_music()
without arguments.SDL::Mixer
functions, nor SDL::Audio::lock, from a callback function.SDL::Mixer::Music::hook_music()
to stop this callback. my $callback = sub
+ {
+ my $position = shift; # position (first time its 0, on each call $length is added)
+ my $length = shift; # length of bytes we have to put in stream
+ my @stream = '';
+
+ printf("position=%8d, stream length=%6d\n", $position, $length);
+
+ for(my $i = 0; $i < $length; $i++)
+ {
+ push(@stream, (($i + $position) & 0xFF));
+ }
+
+ return @stream;
+ };
+
+ SDL::Mixer::Music::hook_music( $callback, 0 );
+
+
hook_music_finished
SDL::Mixer::Music::hook_music_finished( $callback );
+
+
+ my $music_is_playing = 0;
+ my @music = qw(first.mp3 next.mp3 other.mp3 last.mp3);
+ my $callback = sub{ $music_is_playing = 0; };
+ SDL::Mixer::Music::hook_music_finished( $callback );
+
+ foreach my $this_song ( @music )
+ {
+ SDL::Mixer::Music::play_music( $this_song, 0 );
+ $music_is_playing = 1;
+
+ SDL::delay( 100 ) while( $music_is_playing );
+ }
+
+ SDL::Mixer::Music::hook_music_finished(); # cleanup
+
+
get_music_hook_data
my $position = SDL::Mixer::Music::get_music_hook_data();
+
+
+position
(first) parameter that will be passed to hook_music's callback.play_music
@@ -139,6 +176,18 @@ Passing -1 to $loops
will loop the music infinitely.
my $volume_before = SDL::Mixer::Music::volume_music( $new_volume ); + ++
volume_music
set the volume in $new_volume
and returns the volume that was set before.
+Passing -1
as argument causes only to return the current volume.
Volume is between 0
(silence) and MIX_MAX_VOLUME = 128
.
Example:
+# set the music volume to 1/2 maximum, and then check it + printf( "volume was : %d\n", SDL::Mixer::Music::volume_music( MIX_MAX_VOLUME / 2 ) ); + printf( "volume is now : %d\n", SDL::Mixer::Music::volume_music( -1 ) ); + +
Returns 1
if the music is playing sound, otherwise 0
. It does'nt check if the music is paused.
Tobias Leich [FROGGS]
+ +Core | ||
SDL | - Simple DirectMedia Layer for Perl | |
SDL::Time | - a SDL perl extension for managing timers. |
Audio | ||
SDL::Audio | - SDL Bindings for Audio |
Structure | ||
SDL::AudioCVT | - Audio Conversion Structure | |
SDL::AudioSpec | - SDL Bindings for structure SDL::AudioSpec |
CDROM | ||
SDL::CDROM | - SDL Bindings for the CDROM device |
Structure | ||
SDL::CD | - SDL Bindings for structure SDL_CD | |
SDL::CDTrack | - SDL Bindings for structure SDL_CDTrack |
Events | ||
SDL::Events | - Bindings to the Events Category in SDL API |
Structure | ||
SDL::Event | - General event structure |
Joystick | ||
SDL::Joystick | - SDL Bindings for the Joystick device |
Mouse | ||
SDL::Mouse | - SDL Bindings for the Mouse device |
Structure | ||
SDL::Cursor | - Mouse cursor structure |
Structure | ||
SDL::Version | - SDL Bindings for structure SDL_Version |
Video | ||
SDL::Video | - Bindings to the video category in SDL API |
Structure | ||
SDL::Color | - Format independent color description | |
SDL::Overlay | - YUV Video overlay | |
SDL::Palette | - Color palette for 8-bit pixel formats | |
SDL::PixelFormat | - Stores surface format information | |
SDL::Rect | - Defines a rectangular area | |
SDL::Surface | - Graphic surface structure. | |
SDL::VideoInfo | - Video Target Information |
Cookbook | ||
SDL::Cookbook | ||
SDL::Cookbook::PDL |
Extension | ||
SDL::App | - a SDL perl extension |
GFX | ||
SDL::GFX::Framerate | - framerate calculating functions | |
SDL::GFX::Primitives | - basic drawing functions |
Structure | ||
SDL::GFX::FPSManager | - data structure used by SDL::GFX::Framerate |
Image | ||
SDL::Image | - Bindings for the SDL_Image library |
Mixer | ||
SDL::Mixer | - Sound and music functions | |
SDL::Mixer::Channels | - SDL::Mixer channel functions and bindings | |
SDL::Mixer::Effects | - SDL_Mixer sound effect functions and bindings | |
SDL::Mixer::Groups | - SDL_Mixer groups functions and bindings | |
SDL::Mixer::Music | - SDL_Mixer music functions and bindings | |
SDL::Mixer::Samples | - functions for loading sound samples |
Structure | ||
SDL::Mixer::MixChunk | - SDL Bindings for structure SDL_MixChunk | |
SDL::Mixer::MixMusic | - SDL Bindings for structure SDL_MixMusic |
TODO |
Core |
MultiThread | ||
SDL::MultiThread | - Bindings to the MultiThread category in SDL API |
Structure | ||
SDL::RWOps | - SDL Bindings to SDL_RWOPs |
GFX | ||
SDL::GFX::BlitFunc | - blitting functions | |
SDL::GFX::ImageFilter | - image filtering functions | |
SDL::GFX::Rotozoom | - rotation and zooming functions for surfaces |
Tutorials | ||
SDL::Tutorial | - introduction to Perl SDL | |
SDL::Tutorial::Animation | ||
SDL::Tutorial::Images | ||
SDL::Tutorial::LunarLander | - a small tutorial on Perl SDL | |
SDL::Tutorial::Pong | - Get started pong | |
SDL::Tutorial::Tetris | - Let's Make Tetris |
UNCATEGORIZED | ||
SDL::Font | - a SDL perl extension | |
SDL::Game::Palette | - a perl extension | |
SDL::MPEG | - a SDL perl extension | |
SDL::Music | - a perl extension | |
SDL::OpenGL | - a perl extension | |
SDL::SFont | - a perl extension | |
SDL::SMPEG | - a SDL perl extension | |
SDL::Sound | - a perl extension | |
SDL::TTFont | - a SDL perl extension | |
SDL::Tool::Font | - a perl extension | |
SDL::Tool::Graphic |
Core | ||
SDL | - Simple DirectMedia Layer for Perl | |
SDL::Time | - a SDL perl extension for managing timers. |
Audio | ||
SDL::Audio | - SDL Bindings for Audio |
Structure | ||
SDL::AudioCVT | - Audio Conversion Structure | |
SDL::AudioSpec | - SDL Bindings for structure SDL::AudioSpec |
CDROM | ||
SDL::CDROM | - SDL Bindings for the CDROM device |
Structure | ||
SDL::CD | - SDL Bindings for structure SDL_CD | |
SDL::CDTrack | - SDL Bindings for structure SDL_CDTrack |
Events | ||
SDL::Events | - Bindings to the Events Category in SDL API |
Structure | ||
SDL::Event | - General event structure |
Joystick | ||
SDL::Joystick | - SDL Bindings for the Joystick device |
Mouse | ||
SDL::Mouse | - SDL Bindings for the Mouse device |
Structure | ||
SDL::Cursor | - Mouse cursor structure |
Structure | ||
SDL::Version | - SDL Bindings for structure SDL_Version |
Video | ||
SDL::Video | - Bindings to the video category in SDL API |
Structure | ||
SDL::Color | - Format independent color description | |
SDL::Overlay | - YUV Video overlay | |
SDL::Palette | - Color palette for 8-bit pixel formats | |
SDL::PixelFormat | - Stores surface format information | |
SDL::Rect | - Defines a rectangular area | |
SDL::Surface | - Graphic surface structure. | |
SDL::VideoInfo | - Video Target Information |
Cookbook | ||
SDL::Cookbook | ||
SDL::Cookbook::PDL |
Extension | ||
SDL::App | - a SDL perl extension |
GFX | ||
SDL::GFX::Framerate | - framerate calculating functions | |
SDL::GFX::Primitives | - basic drawing functions |
Structure | ||
SDL::GFX::FPSManager | - data structure used by SDL::GFX::Framerate |
Image | ||
SDL::Image | - Bindings for the SDL_Image library |
Mixer | ||
SDL::Mixer | - Sound and music functions | |
SDL::Mixer::Channels | - SDL::Mixer channel functions and bindings | |
SDL::Mixer::Effects | - SDL_Mixer sound effect functions and bindings | |
SDL::Mixer::Groups | - SDL_Mixer groups functions and bindings | |
SDL::Mixer::Music | - functions for music | |
SDL::Mixer::Samples | - functions for loading sound samples |
Structure | ||
SDL::Mixer::MixChunk | - SDL Bindings for structure SDL_MixChunk | |
SDL::Mixer::MixMusic | - SDL Bindings for structure SDL_MixMusic |
TODO |
Core |
MultiThread | ||
SDL::MultiThread | - Bindings to the MultiThread category in SDL API |
Structure | ||
SDL::RWOps | - SDL Bindings to SDL_RWOPs |
GFX | ||
SDL::GFX::BlitFunc | - blitting functions | |
SDL::GFX::ImageFilter | - image filtering functions | |
SDL::GFX::Rotozoom | - rotation and zooming functions for surfaces |
Tutorials | ||
SDL::Tutorial | - introduction to Perl SDL | |
SDL::Tutorial::Animation | ||
SDL::Tutorial::Images | ||
SDL::Tutorial::LunarLander | - a small tutorial on Perl SDL | |
SDL::Tutorial::Pong | - Get started pong | |
SDL::Tutorial::Tetris | - Let's Make Tetris |
UNCATEGORIZED | ||
SDL::Font | - a SDL perl extension | |
SDL::Game::Palette | - a perl extension | |
SDL::MPEG | - a SDL perl extension | |
SDL::Music | - a perl extension | |
SDL::OpenGL | - a perl extension | |
SDL::SFont | - a perl extension | |
SDL::SMPEG | - a SDL perl extension | |
SDL::Sound | - a perl extension | |
SDL::TTFont | - a SDL perl extension | |
SDL::Tool::Font | - a perl extension | |
SDL::Tool::Graphic |