summaryrefslogtreecommitdiffhomepage
path: root/examples/audio_module_playing.c
diff options
context:
space:
mode:
authorvictorfisac <[email protected]>2016-10-06 20:57:31 +0200
committervictorfisac <[email protected]>2016-10-06 20:57:31 +0200
commit2a158c47955d2d849e939152e0c174b02c500104 (patch)
treefbf515597add99255f0e980d7a12ea33a3aa5585 /examples/audio_module_playing.c
parent3e1321ac24743cf3df1c2bb923023f9c222aa250 (diff)
parentdb6538859cd2fabb44f1f29cd87f5b498ca0c2c8 (diff)
downloadraylib-2a158c47955d2d849e939152e0c174b02c500104.tar.gz
raylib-2a158c47955d2d849e939152e0c174b02c500104.zip
Merge remote-tracking branch 'refs/remotes/raysan5/develop' into develop
Diffstat (limited to 'examples/audio_module_playing.c')
-rw-r--r--examples/audio_module_playing.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/examples/audio_module_playing.c b/examples/audio_module_playing.c
index 6189b866..7da3579c 100644
--- a/examples/audio_module_playing.c
+++ b/examples/audio_module_playing.c
@@ -57,9 +57,12 @@ int main()
// Create a RenderTexture2D to be used for render to texture
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
- PlayMusicStream(0, "resources/audio/2t2m_spa.xm"); // Play module stream
+ Music xm = LoadMusicStream("resources/audio/mini1111.xm");
+
+ PlayMusicStream(xm);
float timePlayed = 0.0f;
+ bool pause = false;
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
@@ -69,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;
@@ -86,11 +111,6 @@ int main()
circles[i].speed = (float)GetRandomValue(1, 100)/20000.0f;
}
}
-
- // Get timePlayed scaled to bar dimensions
- timePlayed = (GetMusicTimePlayed(0)/GetMusicTimeLength(0)*(screenWidth - 40))*2;
-
- UpdateMusicStream(0); // Update music buffer with new stream data
//----------------------------------------------------------------------------------
// Draw
@@ -129,6 +149,8 @@ int main()
UnloadShader(shader); // Unload shader
UnloadRenderTexture(target); // Unload render texture
+ UnloadMusicStream(xm); // Unload music stream buffers from RAM
+
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
CloseWindow(); // Close window and OpenGL context