Skip to content
This repository
Browse code

added load_MUS_RW feature, docs and tests

  • Loading branch information...
commit b001a9151d993374747a06d0d6b81c0025505de1 1 parent 7338e3b
Tobias Leich authored December 01, 2011
20  lib/pods/SDL/Mixer/Music.pod
Source Rendered
@@ -17,6 +17,26 @@ Mixer
17 17
 
18 18
 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">.
19 19
 
  20
+=head2 load_MUS_RW
  21
+
  22
+ my $music = SDL::Mixer::Music::load_MUS_RW( $rwops );
  23
+
  24
+C<load_MUS_RW> does the same like C<load_MUS> except that it accepts an L<SDL::RWOps>-object rather than a filename.
  25
+
  26
+Example for loading music from a variable:
  27
+
  28
+ use SDL;
  29
+ use SDL::Mixer;
  30
+ use SDL::Mixer::Music;
  31
+ use SDL::RWOps;
  32
+ 
  33
+ [...]
  34
+ 
  35
+ my $rwops = SDL::RWOps->new_const_mem( $scalar_holding_music );
  36
+ my $music = SDL::Mixer::Music::load_MUS( $rwops );
  37
+
  38
+<b>Noet:</b> You need at least libSDL_mixer 1.2.7 for this feature.
  39
+
20 40
 =head2 hook_music
21 41
 
22 42
  SDL::Mixer::Music::hook_music( $callback, $position );
29  src/Mixer/Music.xs
@@ -123,6 +123,35 @@ mixmus_load_MUS( filename )
123 123
 	OUTPUT:
124 124
 		RETVAL
125 125
 
  126
+#if VERSION_ATLEAST(SDL_MIXER_MAJOR_VERSION, SDL_MIXER_MINOR_VERSION, SDL_MIXER_PATCHLEVEL, 1, 2, 7)
  127
+
  128
+Mix_Music *
  129
+mixmus_load_MUS_RW( rw )
  130
+	SDL_RWops *rw
  131
+	PREINIT:
  132
+		char * CLASS = "SDL::Mixer::MixMusic";
  133
+	CODE:
  134
+		Mix_Music * mixmusic;
  135
+		mixmusic = Mix_LoadMUS_RW(rw);
  136
+		if (mixmusic == NULL)
  137
+			fprintf(stderr, "Could not load SDL::RWOp object\n");
  138
+		RETVAL = mixmusic;
  139
+	OUTPUT:
  140
+		RETVAL
  141
+
  142
+#else
  143
+
  144
+Mix_Music *
  145
+mixmus_load_MUS_RW( rw )
  146
+	SDL_RWops *rw
  147
+	CODE:
  148
+		warn("SDL_mixer >= 1.2.7 needed for SDL::Mixer::Music::load_MUS_RW( rw )");
  149
+		XSRETURN_UNDEF;
  150
+	OUTPUT:
  151
+		RETVAL
  152
+
  153
+#endif
  154
+
126 155
 void
127 156
 mixmus_free_music( music )
128 157
 	Mix_Music *music
14  t/mixer_music.t
@@ -31,6 +31,7 @@ BEGIN {
31 31
 use SDL::Mixer;
32 32
 use SDL::Mixer::Music;
33 33
 use SDL::Mixer::Samples;
  34
+use SDL::RWOps;
34 35
 use SDL::Version;
35 36
 
36 37
 my $v = SDL::Mixer::linked_version();
@@ -110,6 +111,19 @@ is( SDL::Mixer::Music::play_music( $sample_music, 0 ),
110 111
 
111 112
 SKIP:
112 113
 {
  114
+	skip( 'Version 1.2.7 needed', 2 )
  115
+		unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 7 );
  116
+
  117
+	my $rw = SDL::RWOps->new_file( $audio_test_file, "rb" );
  118
+	my $sample_music_rw = SDL::Mixer::Music::load_MUS_RW( $rw );
  119
+	isa_ok( $sample_music_rw, 'SDL::Mixer::MixMusic', '[load_MUS_RW]' );
  120
+	is( SDL::Mixer::Music::play_music( $sample_music_rw, 0 ),
  121
+		0, "[play_music_rw] plays $audio_test_file"
  122
+	);
  123
+}
  124
+
  125
+SKIP:
  126
+{
113 127
 	skip( 'Version 1.2.9 needed', 2 )
114 128
 		unless ( $v->major >= 1 && $v->minor >= 2 && $v->patch >= 9 );
115 129
 

0 notes on commit b001a91

Please sign in to comment.
Something went wrong with that request. Please try again.