aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/audio_module_playing.c30
-rw-r--r--examples/audio_music_stream.c51
2 files changed, 50 insertions, 31 deletions
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
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();
//----------------------------------------------------------------------------------