From 79c8eb543ef93fbfbc4073c6c4ea71e22e7e02c4 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 15 Sep 2016 11:53:16 +0200 Subject: Corrected audio bugs and improved examples --- examples/audio_module_playing.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'examples/audio_module_playing.c') diff --git a/examples/audio_module_playing.c b/examples/audio_module_playing.c index fe9ea15c..7da3579c 100644 --- a/examples/audio_module_playing.c +++ b/examples/audio_module_playing.c @@ -62,6 +62,7 @@ int main() PlayMusicStream(xm); float timePlayed = 0.0f; + bool pause = false; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -71,7 +72,29 @@ int main() { // Update //---------------------------------------------------------------------------------- - for (int i = MAX_CIRCLES - 1; i >= 0; i--) + UpdateMusicStream(xm); // Update music buffer with new stream data + + // Restart music playing (stop and play) + if (IsKeyPressed(KEY_SPACE)) + { + StopMusicStream(xm); + PlayMusicStream(xm); + } + + // Pause/Resume music playing + if (IsKeyPressed(KEY_P)) + { + pause = !pause; + + if (pause) PauseMusicStream(xm); + else ResumeMusicStream(xm); + } + + // Get timePlayed scaled to bar dimensions + timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2; + + // Color circles animation + for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--) { circles[i].alpha += circles[i].speed; circles[i].radius += circles[i].speed*10.0f; @@ -88,11 +111,6 @@ int main() circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f; } } - - // Get timePlayed scaled to bar dimensions - timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2; - - UpdateMusicStream(xm); // Update music buffer with new stream data //---------------------------------------------------------------------------------- // Draw -- cgit v1.2.3