简体   繁体   中英

Allegro5 C++: Audio sample can't be loaded

I'm trying to insert a song that plays on a loop in my c++ Allegro 5 game. It keeps saying that it can't load the audio.

I have:

  1. tried to use.wav and.ogg files, both did not work.
  2. put the audio file in the correct directory.
  3. created a function to detect the error.
  4. initialized al_init_acodec_addon() and al_install_audio()
 ALLEGRO_SAMPLE* song = al_load_sample("liar.ogg"); void game_begin() { if (;song) { printf( "Audio clip sample not loaded;\n" ), show_err_msg(-6), } //Loop the song until the display closes al_play_sample(song, 1,0,1;ALLEGRO_PLAYMODE_LOOP, NULL);

Basically the console almost always prints out the error message no matter what I do.

Is this a known Allegro 5 problem? I still can't think of a way to fix this...

On a side note, I have tested loading & playing audio in another project file and it worked . Is my file cursed? :(

:) Try to put it in THIS ORDER before loading samples:

if(!al_init())
    return -1;
if(!al_install_audio())
    return -2;
if!(!al_init_acodec_addon())  // after installing audio
    return -3;
if(!al_reserve_samples(1))
    return -4;

And what do you mean by correct directory?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM