-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
174 lines (147 loc) · 5.31 KB
/
index.html
File metadata and controls
174 lines (147 loc) · 5.31 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SCE JBL Player</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
max-width: 600px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 10px;
font-size: 14px;
}
button {
padding: 10px 15px;
margin-right: 5px;
margin-bottom: 5px;
cursor: pointer;
}
#message {
margin-top: 10px;
padding: 10px;
display: none;
}
.success {
background: lightgreen;
}
.error {
background: lightcoral;
}
</style>
</head>
<body>
<div>
<h1>SCE JBL Player</h1>
<input type="text" id="urlInput" placeholder="Enter YouTube URL...">
<div>
<button onclick="playNow()">Play Now</button>
<button onclick="addToQueue()">Add To Queue</button>
<button onclick="skipSong()">Skip</button>
<button onclick="stopPlayback()">Stop</button>
</div>
<div id="message"></div>
</div>
<script>
const API_URL = 'http://localhost:6969';
function showMessage(text, isError = false) {
const messageEl = document.getElementById('message');
messageEl.textContent = text;
messageEl.className = isError ? 'error' : 'success';
messageEl.style.display = 'block';
setTimeout(() => {
messageEl.style.display = 'none';
}, 3000);
}
async function playNow() {
const url = document.getElementById('urlInput').value.trim();
if (!url) {
showMessage('Please enter a YouTube URL', true);
return;
}
try {
const response = await fetch(`${API_URL}/queue`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: url,
play_immediately: true
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
showMessage(data.message || 'Playing now!');
document.getElementById('urlInput').value = '';
} catch (error) {
showMessage(`Error: ${error.message}`, true);
}
}
async function addToQueue() {
const url = document.getElementById('urlInput').value.trim();
if (!url) {
showMessage('Please enter a YouTube URL', true);
return;
}
try {
const response = await fetch(`${API_URL}/queue`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
url: url,
play_immediately: false
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
showMessage(data.message || 'Song queued successfully!');
document.getElementById('urlInput').value = '';
} catch (error) {
showMessage(`Error: ${error.message}`, true);
}
}
async function skipSong() {
try {
const response = await fetch(`${API_URL}/skip`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
showMessage(data.message || 'Skipped to next song!');
} catch (error) {
showMessage(`Error: ${error.message}`, true);
}
}
async function stopPlayback() {
try {
const response = await fetch(`${API_URL}/stop`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
showMessage(data.message || 'Playback stopped!');
} catch (error) {
showMessage(`Error: ${error.message}`, true);
}
}
// Allow pressing Enter to play now
document.getElementById('urlInput').addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
playNow();
}
});
</script>
</body>
</html>