-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioStream.cpp
96 lines (82 loc) · 2.48 KB
/
AudioStream.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "AudioStream.h"
#include "Main.h"
#include "Logs.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
using namespace std;
namespace fs = std::filesystem;
HSTREAM audiostream;
//Main.cpp
string returnStr(AnsiString output);
//Logs.cpp
void addLogLine(string exception);
vector<string> streamHistory;
const string audioStreamsPath = "streampath.readerdata";
TForm4 *Form4;
//---------------------------------------------------------------------------
__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void decideToAdd(string currLine) {
bool isExists = false;
for (int i = 0; i < streamHistory.size(); i++) {
if (streamHistory[i] == currLine) {
isExists = true;
break;
}
}
if (!isExists) {
streamHistory.push_back(currLine);
}
}
void getStreamHistory() {
ifstream streamDataFile(mainFolder + "\\" + audioStreamsPath);
string line;
while (getline(streamDataFile, line)) {
decideToAdd(line);
}
streamDataFile.close();
}
void setStreamComboBox(TComboBox *comboBox) {
comboBox->Items->Clear();
for (int i = 0; i < streamHistory.size(); i++) {
comboBox->Items->Add(streamHistory[i].c_str());
}
if (streamHistory.size() > 0) {
comboBox->ItemIndex = comboBox->Items->Count - 1;
}
}
void saveStreamData() {
ofstream streamDataFile(mainFolder + "\\" + audioStreamsPath);
for (int i = 0; i < streamHistory.size(); i++) {
string tempLine = streamHistory[i];
streamDataFile << tempLine << endl;
}
streamDataFile.close();
}
void __fastcall TMainForm::PlayButtonClick(TObject *Sender)
{
string link = returnStr(RadioEdit->Text);
BASS_Init(-1, 44100, BASS_DEVICE_3D, 0, NULL);
audiostream = BASS_StreamCreateURL(PAnsiChar(link.c_str()), 0, 0, NULL, 0);
if (BASS_ChannelPlay(audiostream, false)) {
decideToAdd(link);
setStreamComboBox(RadioEdit);
saveStreamData();
}
else {
addLogLine("Wrong audiostream link.");
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PauseButtonClick(TObject *Sender)
{
BASS_ChannelPause(audiostream);
}
//---------------------------------------------------------------------------