2 Replies - 199 Views - Last Post: 07 February 2018 - 12:41 PM Rate Topic: -----

#1 Cioscos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-February 18

SDL program (audio)

Posted 07 February 2018 - 03:35 AM

Hi! I have never used the sdl libraries, so I don't know its functions. For now i want only create a C console program that allows me to reproduce an mp3 file. I've already installed SDL2 and SDL_mixer libreries and I found on internet this code:
#include "SDL2/SDL.h"
#include "SDL2/SDL_mixer.h"

static const char *MY_COOL_MP3 = "cool_tunes.mp3";

int main(int argc, char **argv) {
    int result = 0;
    int flags = MIX_INIT_MP3;

    if (SDL_Init(SDL_INIT_AUDIO) < 0) {
        printf("Failed to init SDL\n");
        exit(1);
    }

    if (flags != (result = Mix_Init(flags))) {
        printf("Could not initialize mixer (result: %d).\n", result);
        printf("Mix_Init: %s\n", Mix_GetError());
        exit(1);
    }

    Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 640);
    Mix_Music *music = Mix_LoadMUS(MY_COOL_MP3);
    Mix_PlayMusic(music, 1);

    while (!SDL_QuitRequested()) {
        SDL_Delay(250);
    }

    Mix_FreeMusic(music);
    SDL_Quit();
    return 0;
}


Now.. when i execute the program, I get an error:
[img]https://imgur.com/PoJWG3u[/img]
Someone can help me? Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: SDL program (audio)

#2 Cioscos  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-February 18

Re: SDL program (audio)

Posted 07 February 2018 - 03:55 AM

Posted Image
Was This Post Helpful? 0
  • +
  • -

#3 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1437
  • View blog
  • Posts: 4,621
  • Joined: 20-March 10

Re: SDL program (audio)

Posted 07 February 2018 - 12:41 PM

sdl2_mixer relies on libmpeg
for mp3 support.

This post has been edited by snoopy11: 07 February 2018 - 12:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1