MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/audio/audio_music_stream.cpp:14–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12#include "raylib-cpp.hpp"
13
14int 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);

Callers

nothing calls this directly

Calls 9

IsKeyPressedFunction · 0.85
PlayMethod · 0.80
ShouldCloseMethod · 0.80
GetTimePlayedMethod · 0.80
GetTimeLengthMethod · 0.80
DrawTextFunction · 0.50
DrawRectangleFunction · 0.50
DrawRectangleLinesFunction · 0.50
UpdateMethod · 0.45

Tested by

no test coverage detected