Here the simpliest way to play an audio file. You just open the file and load it in the waave engine :
/* open the audio file */ WVStream* stream = WV_getStream(filename); /* check file type */ int streamType = WV_getStreamType(stream); if(streamType != WV_STREAM_TYPE_AUDIO) return 0; //not an audio file /* load */ WV_loadStream(stream);
You can now play, pause ..., the stream when you want :
/* play */ WV_playStream(stream);
Before loading the stream you can set playing attibutes.
/* check file type */ int streamType = WV_getStreamType(stream); if(streamType == WV_STREAM_TYPE_AUDIOVIDEO) WV_disableVideo(stream);
/* enable looping play */ WV_setEOFMethod(stream, WV_LOOPING_STREAM);
/* disable looping play */ WV_setEOFMethod(stream, WV_BLOCKING_STREAM);
/* if the stream is paused, seek cause restart playing */ WV_setSeekMethod(stream, WV_PLAYING_SEEK); /* if the stream is paused, it stay paused after the seek */ WV_setSeekMethod(stream, WV_BLOCKING_SEEK);
/* if play command is sended while the stream is playing, it do nothing */ WV_setPlayMethod(stream, WV_NEUTRAL_PLAY); /* if play command is sended while the stream is playing, it restart at the beginning */ WV_setPlayMethod(stream, WV_LOOPING_PLAY);
You will receive an WV_EOF_EVENT when the end of a stream is reached. To know to witch stream the event refer see the event.user.data1 field.
/* check event */ switch( event.type ) { case SDL_EOF_EVENT: endedStream = event.user.data1; // do whant you want break; ... }