MCPcopy Create free account
hub / github.com/SFML/SFML / playMusic

Function playMusic

examples/sound/Sound.cpp:48–73  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Play a music ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

46///
47////////////////////////////////////////////////////////////
48void playMusic(const std::filesystem::path& filename)
49{
50 // Load an ogg music file
51 sf::Music music("resources" / filename);
52
53 // Display music information
54 std::cout << filename << ":" << '\n'
55 << " " << music.getDuration().asSeconds() << " seconds" << '\n'
56 << " " << music.getSampleRate() << " samples / sec" << '\n'
57 << " " << music.getChannelCount() << " channels" << '\n';
58
59 // Play it
60 music.play();
61
62 // Loop while the music is playing
63 while (music.getStatus() == sf::Music::Status::Playing)
64 {
65 // Leave some CPU time for other processes
66 sf::sleep(sf::milliseconds(100));
67
68 // Display the playing position
69 std::cout << "\rPlaying... " << music.getPlayingOffset().asSeconds() << " sec " << std::flush;
70 }
71
72 std::cout << '\n' << std::endl;
73}
74} // namespace
75
76

Callers 1

mainFunction · 0.85

Calls 7

sleepFunction · 0.85
getDurationMethod · 0.45
getSampleRateMethod · 0.45
getChannelCountMethod · 0.45
playMethod · 0.45
getStatusMethod · 0.45
getPlayingOffsetMethod · 0.45

Tested by

no test coverage detected