I'm trying to use SDL_Mixer to create a sound/music player for a game engine. But I can't get it to load a music file. Can anyone tell me what I'm doing wrong with this example?
Code:
unit music_player;
interface
uses sdl, sdl_mixer, sdl_sound;
type
TMyMediaPlayer = class(TObject)
private
FBgm: string;
FBgmLooped: boolean;
public
constructor create;
procedure playMusic(filename: string);
end;
implementation
uses sysUtils;
{ TMyMediaPlayer }
constructor TMyMediaPlayer.create;
begin
FBgm := '';
SDL_Init(SDL_INIT_AUDIO);
assert(Mix_OpenAudio(44100, AUDIO_S16, 4, 8192) <> 0);
end;
procedure TMyMediaPlayer.playMusic(filename: string);
var
music: PMix_Music;
begin
********
music := Mix_LoadMUS(PChar(filename));
********
Mix_PlayMusic(music, -1);
FBgmLooped := false;
end;
end.
I put *s around the line that's giving me trouble. After I initialize everything and call playMusic, Mix_LoadMUS returns nil. The filename I passed in exists, and it's just a WAV file. Any idea why this isn't loading?
Mason
Bookmarks