2014-04-19 18:54:48 +04:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2014-09-21 16:26:42 +04:00
|
|
|
* raylib [audio] example - Music playing (streaming)
|
2014-04-19 18:54:48 +04:00
|
|
|
*
|
2014-09-21 16:26:42 +04:00
|
|
|
* NOTE: This example requires OpenAL Soft library installed
|
2014-04-19 18:54:48 +04:00
|
|
|
*
|
2014-09-21 16:26:42 +04:00
|
|
|
* This example has been created using raylib 1.1 (www.raylib.com)
|
2014-04-19 18:54:48 +04:00
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
int screenWidth = 800;
|
|
|
|
int screenHeight = 450;
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)");
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
InitAudioDevice(); // Initialize audio device
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
int framesCounter = 0;
|
|
|
|
float volume = 1.0;
|
|
|
|
float timePlayed = 0;
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2014-04-19 18:54:48 +04:00
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
framesCounter++;
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-09-21 16:26:42 +04:00
|
|
|
// Testing music fading from one file to another
|
2014-04-19 18:54:48 +04:00
|
|
|
/*
|
2014-09-21 16:26:42 +04:00
|
|
|
if (framesCounter > 600) // Wait for 10 seconds (600 frames)
|
2014-04-19 18:54:48 +04:00
|
|
|
{
|
2014-09-21 16:26:42 +04:00
|
|
|
volume -= 0.01; // Decrement music volume level
|
2014-09-30 01:41:05 +04:00
|
|
|
|
|
|
|
// When music volume level equal or lower than 0,
|
2014-09-21 16:26:42 +04:00
|
|
|
// restore volume level and init another music file
|
2014-09-30 01:41:05 +04:00
|
|
|
if (volume <= 0)
|
2014-04-19 18:54:48 +04:00
|
|
|
{
|
|
|
|
volume = 1.0;
|
2014-09-21 16:26:42 +04:00
|
|
|
framesCounter = 0;
|
|
|
|
PlayMusicStream("resources/audio/another_file.ogg");
|
2014-04-19 18:54:48 +04:00
|
|
|
}
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
SetMusicVolume(volume);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4; // We scale by 4 to fit 400 pixels
|
|
|
|
//----------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
ClearBackground(RAYWHITE);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
DrawText("MUSIC SHOULD BE PLAYING!", 255, 200, 20, LIGHTGRAY);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
DrawRectangle(200, 250, 400, 12, LIGHTGRAY);
|
|
|
|
DrawRectangle(200, 250, (int)timePlayed, 12, MAROON);
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CloseAudioDevice(); // Close audio device (music streaming is automatically stopped)
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
2014-09-30 01:41:05 +04:00
|
|
|
|
2014-04-19 18:54:48 +04:00
|
|
|
return 0;
|
|
|
|
}
|