#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include “SDL.h”
#include “SDL_mixer.h”
int main(int argc, char **argv)
{
//parse cmd para
if(argc != 2){
fprintf(stderr, “%s filename.\n”, argv[0]);
exit(-1);
}
//init SDL
if(SDL_Init(SDL_INIT_AUDIO) == -1){
fprintf(stderr, "sdl init:%s\n", Mix_GetError());
exit(-1);
}
atexit(SDL_Quit);
//check audio driver name
char buffer[32];
fprintf(stderr, "audio driver:%s\n", SDL_AudioDriverName(buffer, 32));
//init SDL_mixer
if(Mix_OpenAudio(44100, AUDIO_S16LSB, 1, 4096) == -1){
fprintf(stderr, "open audio error:%s\n", Mix_GetError());
exit(-1);
}
// load music file
Mix_Music *music;
music=Mix_LoadMUS(argv[1]);
if(!music){
printf("Mix_LoadMUS: %s\n", Mix_GetError());
return 0;
}
// play music, 2+1 times.
if(Mix_PlayMusic(music, 0)==-1){
printf("Mix_PlayMusic: %s\n", Mix_GetError());
}
//check if playing, print log
if(Mix_PlayingMusic()){
printf("music is playing...\n");
}
//wait until the music over, do nothing, just wait.
while(Mix_PlayingMusic()){
//
}
//now, music is over
printf("music play over,exiting\n");
//cleanup
Mix_FreeMusic(music);
Mix_CloseAudio();
return 0;
}
this is my music player src, when the player runs on PC,all OK?
but?on my board(Linux OS, OSS audio driver)?plays only a while, the player app will exit.
I have no ideal about it.
cat test.wav > /dev/dsp works well;so the oss driver is no problem.
test.wav is below:
RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 22050 Hz–
???
@guoyong.lei_at_163.c
???
???15909866103
???15909866103