diff options
| author | raysan5 <[email protected]> | 2016-09-15 11:53:16 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2016-09-15 11:53:16 +0200 |
| commit | 79c8eb543ef93fbfbc4073c6c4ea71e22e7e02c4 (patch) | |
| tree | 03c6c40184cb26776b8e9ed52d06f73fe5c007a5 /examples/audio_music_stream.c | |
| parent | 9923fe51a7f69f94c765cfe0dbbf718f287a7a2f (diff) | |
| download | raylib-79c8eb543ef93fbfbc4073c6c4ea71e22e7e02c4.tar.gz raylib-79c8eb543ef93fbfbc4073c6c4ea71e22e7e02c4.zip | |
Corrected audio bugs and improved examples
Diffstat (limited to 'examples/audio_music_stream.c')
| -rw-r--r-- | examples/audio_music_stream.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/examples/audio_music_stream.c b/examples/audio_music_stream.c index c552d030..dc9d4355 100644 --- a/examples/audio_music_stream.c +++ b/examples/audio_music_stream.c @@ -28,9 +28,8 @@ int main() PlayMusicStream(music); - int framesCounter = 0; float timePlayed = 0.0f; - //float volume = 1.0; + bool pause = false; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -40,28 +39,26 @@ int main() { // Update //---------------------------------------------------------------------------------- - framesCounter++; - - // Testing music fading from one file to another -/* - if (framesCounter > 600) // Wait for 10 seconds (600 frames) + UpdateMusicStream(music); // Update music buffer with new stream data + + // Restart music playing (stop and play) + if (IsKeyPressed(KEY_SPACE)) { - volume -= 0.01; // Decrement music volume level - - // When music volume level equal or lower than 0, - // restore volume level and init another music file - if (volume <= 0) - { - volume = 1.0; - framesCounter = 0; - } - - SetMusicVolume(volume); + StopMusicStream(music); + PlayMusicStream(music); } -*/ - timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4; // We scale by 4 to fit 400 pixels - - UpdateMusicStream(music); // Update music buffer with new stream data + + // Pause/Resume music playing + if (IsKeyPressed(KEY_P)) + { + pause = !pause; + + if (pause) PauseMusicStream(music); + else ResumeMusicStream(music); + } + + // Get timePlayed scaled to bar dimensions (400 pixels) + timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4; //---------------------------------------------------------------------------------- // Draw @@ -70,10 +67,14 @@ int main() ClearBackground(RAYWHITE); - DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY); + DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); - DrawRectangle(200, 250, 400, 12, LIGHTGRAY); - DrawRectangle(200, 250, (int)timePlayed, 12, MAROON); + DrawRectangle(200, 200, 400, 12, LIGHTGRAY); + DrawRectangle(200, 200, (int)timePlayed, 12, MAROON); + DrawRectangleLines(200, 200, 400, 12, GRAY); + + DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, LIGHTGRAY); + DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- |
