Skip to content

Commit 7aa19fb

Browse files
committed
implemented HTML volume progressbar
1 parent 85e3fd7 commit 7aa19fb

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

mainapp.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,28 @@ std::mutex httpServerMutex;
1414

1515
std::string lastInsertChannel = "";
1616

17+
int VolumeProgressRunning = false;
18+
int VolumeWaitCount;
19+
20+
void hideVolumebar() {
21+
// int waitTime = 100;
22+
int waitTime = 60;
23+
VolumeWaitCount = 0;
24+
VolumeProgressRunning = true;
25+
26+
while (VolumeWaitCount < 50) {
27+
VolumeWaitCount++;
28+
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
29+
}
30+
31+
auto frame = currentBrowser->GetMainFrame();
32+
if (frame != nullptr) {
33+
frame->ExecuteJavaScript("document.getElementById('_volumecontainer').style.visibility= \"hidden\";", frame->GetURL(), 0);
34+
}
35+
36+
VolumeProgressRunning = false;
37+
}
38+
1739
void startHttpServer(std::string browserIp, int browserPort, std::string vdrIp, int vdrPort, std::string transcoderIp, int transcoderPort) {
1840
int _browserPort = browserPort;
1941
std::string _browserIp = browserIp;
@@ -264,7 +286,21 @@ void startHttpServer(std::string browserIp, int browserPort, std::string vdrIp,
264286
if (cv.empty() || mv.empty()) {
265287
res.status = 404;
266288
} else {
267-
// TODO: Implement some HTML Widget which shows the current volume
289+
auto frame = currentBrowser->GetMainFrame();
290+
291+
if (frame != nullptr) { // Why is it possible, that MainFrame is null?
292+
frame->ExecuteJavaScript("document.getElementById('_volumecontainer').style.visibility= \"visible\";", frame->GetURL(), 0);
293+
frame->ExecuteJavaScript("document.getElementById('_volume').value = \"" + cv + "\";", frame->GetURL(), 0);
294+
frame->ExecuteJavaScript("document.getElementById('_volume').max = \"" + mv + "\";", frame->GetURL(), 0);
295+
296+
if (VolumeProgressRunning) {
297+
VolumeWaitCount = 0;
298+
} else {
299+
std::thread hideThread(hideVolumebar);
300+
hideThread.detach();
301+
}
302+
}
303+
268304
res.set_content("ok", "text/plain");
269305
}
270306
});

requestresponse.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::string readPreJavascript(std::string browserIp, int browserPort) {
4545

4646
std::string readPreCSS(std::string browserIp, int browserPort) {
4747
std::string result;
48-
std::string files[] = { "TiresiasPCfont.css" };
48+
std::string files[] = { "TiresiasPCfont.css", "volume.css" };
4949

5050
for (const auto & file : files) {
5151
result += readFile(("css/" + file).c_str());
@@ -74,6 +74,8 @@ std::string readPostJavascript(std::string browserIp, int browserPort) {
7474

7575
std::string post = "\n<script type=\"text/javascript\" src=\"http://" + browserIp + ":" + std::to_string(browserPort) + "/js/_dynamic_body.js\"></script>\n";
7676

77+
post += "<div id=\"_volumecontainer\" style=\"visibility: hidden;\"><progress value=\"0\" max=\"100\" id=\"_volume\"></progress></div>\n";
78+
7779
return post;
7880
}
7981

static-content/css/volume.css

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#_volumecontainer {
2+
width: 100%;
3+
position: absolute;
4+
left: 0px;
5+
top: 0px;
6+
}
7+
8+
#_volume {
9+
width: 100%;
10+
}

0 commit comments

Comments
 (0)