| 12 | #include "raylib-cpp.hpp" |
| 13 | |
| 14 | int main() { |
| 15 | // Initialization |
| 16 | //-------------------------------------------------------------------------------------- |
| 17 | const int screenWidth = 800; |
| 18 | const int screenHeight = 450; |
| 19 | |
| 20 | raylib::Window window(screenWidth, screenHeight, "raylib [audio] example - music playing (streaming)"); |
| 21 | |
| 22 | raylib::AudioDevice audio; // Initialize audio device |
| 23 | |
| 24 | raylib::Music music("resources/target.ogg"); |
| 25 | |
| 26 | music.Play(); |
| 27 | |
| 28 | float timePlayed = 0.0f; |
| 29 | bool pause = false; |
| 30 | |
| 31 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
| 32 | //-------------------------------------------------------------------------------------- |
| 33 | |
| 34 | // Main game loop |
| 35 | while (!window.ShouldClose()) { // Detect window close button or ESC key |
| 36 | // Update |
| 37 | //---------------------------------------------------------------------------------- |
| 38 | music.Update(); // Update music buffer with new stream data |
| 39 | |
| 40 | // Restart music playing (stop and play) |
| 41 | if (IsKeyPressed(KEY_SPACE)) { |
| 42 | music.Stop(); |
| 43 | music.Play(); |
| 44 | } |
| 45 | |
| 46 | // Pause/Resume music playing |
| 47 | if (IsKeyPressed(KEY_P)) { |
| 48 | pause = !pause; |
| 49 | |
| 50 | if (pause) { |
| 51 | music.Pause(); |
| 52 | } else { |
| 53 | music.Resume(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Get timePlayed scaled to bar dimensions (400 pixels) |
| 58 | timePlayed = music.GetTimePlayed() / music.GetTimeLength() * 400; |
| 59 | |
| 60 | if (timePlayed > 400) music.Stop(); |
| 61 | //---------------------------------------------------------------------------------- |
| 62 | |
| 63 | // Draw |
| 64 | //---------------------------------------------------------------------------------- |
| 65 | BeginDrawing(); |
| 66 | { |
| 67 | window.ClearBackground(RAYWHITE); |
| 68 | |
| 69 | DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, LIGHTGRAY); |
| 70 | |
| 71 | DrawRectangle(200, 200, 400, 12, LIGHTGRAY); |
nothing calls this directly
no test coverage detected