-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicPlayer.cpp
More file actions
37 lines (33 loc) · 869 Bytes
/
Copy pathMusicPlayer.cpp
File metadata and controls
37 lines (33 loc) · 869 Bytes
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
#include "MusicPlayer.h"
MusicPlayer::MusicPlayer() {}
void MusicPlayer::Play() {
if (!playList.tracks.empty()) {
if (isStopped) {
if (stream.loadFromFile(playList.tracks[playList.currentIndex].path)) {
stream.setVolume(volume);
stream.play();
isPlaying = true;
isStopped = false;
}
}
else if (!isPlaying) {
stream.play();
isPlaying = true;
}
}
}
void MusicPlayer::Pause() {
stream.pause();
isPlaying = false;
isStopped = false;
}
void MusicPlayer::Stop() {
stream.stop();
isPlaying = false;
isStopped = true;
}
float MusicPlayer::getVolume() const { return volume; }
void MusicPlayer::setVolume(float v) {
volume = std::max(0.0f, std::min(100.0f, v));
stream.setVolume(volume);
}