/////////////////////////////////////////////////////// Play a music ///////////////////////////////////////////////////////
| 46 | /// |
| 47 | //////////////////////////////////////////////////////////// |
| 48 | void 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 |
no test coverage detected