-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
80 lines (68 loc) · 2.65 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <implementation/FFSource.h>
#include <memory>
#include <implementation/SampleRateConverter.h>
#include <implementation/RtAudioRenderer.h>
#include <implementation/AudioPlayerImpl.h>
#include <structs/events/PlaybackErrorEvent.h>
#include <thread>
#include <mutex>
#include <condition_variable>
std::mutex waitForCommandMutex;
std::condition_variable waitForCommand;
class EventReceiver: public CasperTech::IAudioPlayerEventReceiver
{
void onPlayerEvent(const std::shared_ptr<CasperTech::PlayerEvent>& event) override
{
if (event->eventType != EventType::Command)
{
if (event->eventType == EventType::PlaybackError)
{
auto evt = std::static_pointer_cast<CasperTech::PlaybackErrorEvent>(event);
std::cout << "Got error " << evt->msg << std::endl;
}
std::cout << "Got event " << unsigned(event->eventType) << std::endl;
}
}
};
void commandDone(CommandResult result, const std::string& errorMessage)
{
std::cout << errorMessage << std::endl;
std::unique_lock<std::mutex> lk(waitForCommandMutex);
waitForCommand.notify_one();
}
int main()
{
std::unique_lock<std::mutex> wait(waitForCommandMutex);
auto recv = new EventReceiver();
auto player = std::make_shared<CasperTech::AudioPlayerImpl>(recv);
std::cout << "Loading File" << std::endl;
player->load(R"(C:\Projects\@caspertech\node-audio\media\piano.wav)", &commandDone);
waitForCommand.wait(wait);
std::cout << "Fileloaded. Seeking to 2 seconds" << std::endl;
player->seek(2000, &commandDone);
waitForCommand.wait(wait);
std::cout << "Waiting for 2 seconds before playing" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
std::cout << "Playing for 2.0 seconds befor seeking back to 0" << std::endl;
player->play(&commandDone);
waitForCommand.wait(wait);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
player.reset();
/*
player->seek(0, &commandDone);
waitForCommand.wait(wait);
std::cout << "Waiting for 5 seconds then seeking back to 0" << std::endl;;
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
player->seek(0, &commandDone);
waitForCommand.wait(wait);
std::cout << "Waiting for 5 seconds then setting volume to 0.1" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
player->setVolume(0.1f, &commandDone);
waitForCommand.wait(wait);
std::cout << "Done" << std::endl;
*/
while (1)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}