Now I can play a sound! Yay!
This commit is contained in:
parent
f83c0c7ff9
commit
7309ec2f40
7 changed files with 47 additions and 8 deletions
32
audiotest.cpp
Normal file
32
audiotest.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <SFML/Audio.hpp>
|
||||
#include <thread> // for sleep_for
|
||||
#include <iostream>
|
||||
#include <fmt/core.h>
|
||||
#include <chrono>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
sf::SoundBuffer buffer;
|
||||
sf::Sound click;
|
||||
|
||||
if(argc != 2) {
|
||||
fmt::println("USAGE: audiotest click.mp3");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *in_file = argv[1];
|
||||
|
||||
if(!buffer.loadFromFile(in_file)) {
|
||||
fmt::println("Failed to load {}", in_file);
|
||||
}
|
||||
|
||||
click.setBuffer(buffer);
|
||||
|
||||
fmt::println("Playing {}. Hit ctrl-c to exit.", in_file);
|
||||
|
||||
while(true) {
|
||||
click.play();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue