Permalink
Browse files

added load_MUS_RW feature, docs and tests

  • Loading branch information...
FROGGS committed Dec 1, 2011
1 parent 7338e3b commit b001a9151d993374747a06d0d6b81c0025505de1
Showing with 63 additions and 0 deletions.
  1. +20 −0 lib/pods/SDL/Mixer/Music.pod
  2. +29 −0 src/Mixer/Music.xs
  3. +14 −0 t/mixer_music.t
@@ -17,6 +17,26 @@ Mixer
C<load_MUS> loads a music file into a C<SDL::Mixer::MixMusic> structure. This can be passed to L<play_music|SDL::Mixer::Music/"play_music">.
+=head2 load_MUS_RW
+
+ my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );
+
+C<load_MUS_RW> does the same like C<load_MUS> except that it accepts an L<SDL::RWOps>-object rather than a filename.
+
+Example for loading music from a variable:
+
+ 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 );
+
+<b>Noet:</b> You need at least libSDL_mixer 1.2.7 for this feature.
+
=head2 hook_music
SDL::Mixer::Music::hook_music( $callback, $position );
View
@@ -123,6 +123,35 @@ mixmus_load_MUS( filename )
OUTPUT:
RETVAL
+#if VERSION_ATLEAST(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL, 1, 2, 7)
+
+Mix_Music *
+mixmus_load_MUS_RW( rw )
+ SDL_RWops *rw
+ PREINIT:
+ char * CLASS = "SDL::Mixer::MixMusic";
+ CODE:
+ Mix_Music * mixmusic;
+ mixmusic = Mix_LoadMUS_RW(rw);
+ if (mixmusic == NULL)
+ fprintf(stderr, "Could not load SDL::RWOp object\n");
+ RETVAL = mixmusic;
+ OUTPUT:
+ RETVAL
+
+#else
+
+Mix_Music *
+mixmus_load_MUS_RW( rw )
+ SDL_RWops *rw
+ CODE:
+ warn("SDL_mixer >= 1.2.7 needed for SDL::Mixer::Music::load_MUS_RW( rw )");
+ XSRETURN_UNDEF;
+ OUTPUT:
+ RETVAL
+
+#endif
+
void
mixmus_free_music( music )
Mix_Music *music
View
@@ -31,6 +31,7 @@ BEGIN {
use SDL::Mixer;
use SDL::Mixer::Music;
use SDL::Mixer::Samples;
+use SDL::RWOps;
use SDL::Version;
my $v = SDL::Mixer::linked_version();
@@ -108,6 +109,19 @@ is( SDL::Mixer::Music::play_music( $sample_music, 0 ),
0, "[play_music] plays $audio_test_file"
);
+SKIP:
+{
+ skip( 'Version 1.2.7 needed', 2 )
+ unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 7 );
+
+ my $rw = SDL::RWOps->new_file( $audio_test_file, "rb" );
+ my $sample_music_rw = SDL::Mixer::Music::load_MUS_RW( $rw );
+ isa_ok( $sample_music_rw, 'SDL::Mixer::MixMusic', '[load_MUS_RW]' );
+ is( SDL::Mixer::Music::play_music( $sample_music_rw, 0 ),
+ 0, "[play_music_rw] plays $audio_test_file"
+ );
+}
+
SKIP:
{
skip( 'Version 1.2.9 needed', 2 )

0 comments on commit b001a91

Please sign in to comment.