This repository was archived by the owner on Mar 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
353 lines (307 loc) · 11.9 KB
/
Form1.cs
File metadata and controls
353 lines (307 loc) · 11.9 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
using NAudio.Wave;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NikRadofemPlayerWindows
{
public partial class Form1 : Form
{
// Player
private IWavePlayer waveOut;
private MediaFoundationReader audioFileReader;
private bool isPlaying = false;
private const string StreamUrl = "https://live.nikradofem.online/live";
private const string StatsUrl = "https://live.nikradofem.online/status-json.xsl";
// History
private List<string> trackHistory = new List<string>();
private string lastTrackName = "";
public Form1()
{
InitializeComponent();
try
{
FontHelper.LoadFont("NikRadofemPlayerWindows.Fonts.NEOPIXEL.ttf");
lblTrackName.Font = FontHelper.GetFont(28f, FontStyle.Bold);
}
catch (Exception ex)
{
MessageBox.Show("Íå óäàëîñü çàãðóçèòü øðèôò: " + ex.Message);
}
// --- DISAIN ---
// 1. TrackName
lblTrackName.Parent = pictureBox5;
lblTrackName.BackColor = Color.Transparent;
lblTrackName.AutoSize = false;
lblTrackName.Size = pictureBox5.Size;
lblTrackName.Location = new Point(0, 0);
lblTrackName.TextAlign = ContentAlignment.MiddleCenter;
// 2. TrackBar
modernTrackBar1.Parent = pictureBox4;
modernTrackBar1.BackColor = Color.FromArgb(16, 16, 16);
modernTrackBar1.TrackColor = Color.FromArgb(60, 60, 60);
modernTrackBar1.ProgressColor = Color.FromArgb(0, 255, 0);
modernTrackBar1.Height = 30;
modernTrackBar1.Scroll += ModernTrackBar1_Scroll;
modernTrackBar1.Value = NikRadofemPlayerWindows.Properties.Settings.Default.UserVolume;
// 3. Play button
btnPlayPausePicture.Parent = pictureBox4;
btnPlayPausePicture.BackColor = Color.Transparent;
btnPlayPausePicture.BringToFront();
// Place
modernTrackBar1.Location = new Point(
(pictureBox4.Width - modernTrackBar1.Width) / 2,
pictureBox5.Bottom - 60
);
btnPlayPausePicture.Location = new Point(
(pictureBox4.Width - btnPlayPausePicture.Width) / 2,
modernTrackBar1.Bottom + 10
);
// Timer
timer1.Interval = 5000;
timer1.Tick += Timer1_Tick;
// Volume saves
int savedVolume = NikRadofemPlayerWindows.Properties.Settings.Default.UserVolume;
modernTrackBar1.Value = savedVolume;
}
private void PlayRadio()
{
try
{
audioFileReader = new MediaFoundationReader(StreamUrl);
waveOut = new WaveOutEvent();
waveOut.Init(audioFileReader);
if (modernTrackBar1 != null)
waveOut.Volume = modernTrackBar1.Value / 100f;
waveOut.Play();
isPlaying = true;
btnPlayPausePicture.Image =
NikRadofemPlayerWindows.Properties.Resources.pause_icon;
// Memory TrackName reset
lastTrackName = "";
// Loading
lblTrackName.Text = "Çàãðóçêà...";
timer1.Start();
GetTrackName();
}
catch (Exception ex)
{
MessageBox.Show("Îøèáêà: " + ex.Message);
}
}
private void StopRadio()
{
if (waveOut != null)
{
waveOut.Stop();
waveOut.Dispose();
waveOut = null;
}
if (audioFileReader != null)
{
audioFileReader.Dispose();
audioFileReader = null;
}
isPlaying = false;
btnPlayPausePicture.Image =
NikRadofemPlayerWindows.Properties.Resources.play_icon;
lblTrackName.Text = "Ðàäèî âûêëþ÷åíî";
timer1.Stop();
}
// TrackName restore
private async void Timer1_Tick(object sender, EventArgs e)
{
await GetTrackName();
}
private async Task GetTrackName()
{
try
{
using (HttpClient client = new HttpClient())
{
string jsonResponse = await client.GetStringAsync(StatsUrl);
using (JsonDocument doc = JsonDocument.Parse(jsonResponse))
{
var root = doc.RootElement;
if (root.TryGetProperty("icestats", out var icestats))
{
if (icestats.TryGetProperty("source", out var source))
{
JsonElement currentSource;
if (source.ValueKind == JsonValueKind.Array)
currentSource = source[0];
else
currentSource = source;
if (currentSource.TryGetProperty("title", out var titleElement))
{
string currentTitle = titleElement.GetString();
if (!string.IsNullOrEmpty(currentTitle) && currentTitle != lastTrackName)
{
if (!string.IsNullOrEmpty(lastTrackName) && lastTrackName != "Çàãðóçêà...")
{
string time = DateTime.Now.ToString("HH:mm");
trackHistory.Insert(0, $"[{time}] {lastTrackName}");
if (trackHistory.Count > 20)
{
trackHistory.RemoveAt(trackHistory.Count - 1);
}
}
lastTrackName = currentTitle;
lblTrackName.Text = currentTitle;
notifyIcon1.ShowBalloonTip(3000, "Ñåé÷àñ èãðàåò:", currentTitle, ToolTipIcon.Info);
}
else if (string.IsNullOrEmpty(currentTitle))
{
lblTrackName.Text = "Íåò äàííûõ";
}
}
}
}
}
}
}
catch
{
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
NikRadofemPlayerWindows.Properties.Settings.Default.UserVolume = modernTrackBar1.Value;
NikRadofemPlayerWindows.Properties.Settings.Default.Save();
StopRadio();
base.OnFormClosing(e);
}
private void ModernTrackBar1_Scroll(object sender, EventArgs e)
{
NikRadofemPlayerWindows.Properties.Settings.Default.UserVolume = modernTrackBar1.Value;
NikRadofemPlayerWindows.Properties.Settings.Default.Save();
if (waveOut != null)
{
waveOut.Volume = modernTrackBar1.Value / 100f;
}
}
private void lblTrackName_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
string url = "https://tunein.com/radio/NikRadofem-s346252/";
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show("Íå óäàëîñü îòêðûòü ññûëêó: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox2_Click(object sender, EventArgs e)
{
string url = "https://t.me/Nik3310_Offical";
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show("Íå óäàëîñü îòêðûòü ññûëêó: " + ex.Message);
}
}
private void pictureBox3_Click(object sender, EventArgs e)
{
string url = "https://aboutnikkk.carrd.co/";
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show("Íå óäàëîñü îòêðûòü ññûëêó: " + ex.Message);
}
}
private void btnPlayPausePicture_Click(object sender, EventArgs e)
{
if (isPlaying)
{
StopRadio();
}
else
{
PlayRadio();
}
}
private void pictureBox4_Click(object sender, EventArgs e)
{
}
private void pictureBoxSettings_Click(object sender, EventArgs e)
{
SettingsForm settingsWindow = new SettingsForm();
settingsWindow.ShowDialog();
}
private void pictureBox7_Click(object sender, EventArgs e)
{
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.Filter = "Ïëåéëèñò (*.m3u)|*.m3u"; // Only save .m3u file
saveDialog.FileName = "NikRadofem.m3u"; // Defalt name for .m3u
saveDialog.Title = "Ñîõðàíèòü ïëåéëèñò ðàäèî";
if (saveDialog.ShowDialog() == DialogResult.OK)
{
try
{
string m3uContent = "#EXTM3U\n" +
"#EXTINF:-1,NikRadofem Radio\n" +
StreamUrl;
System.IO.File.WriteAllText(saveDialog.FileName, m3uContent);
MessageBox.Show("Ôàéë óñïåøíî ñîõðàíåí!", "Ãîòîâî", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("Îøèáêà ïðè ñîõðàíåíèè: " + ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void btnHistory_Click(object sender, EventArgs e)
{
HistoryForm historyWindow = new HistoryForm(trackHistory);
historyWindow.ShowDialog();
}
private void btnDonate_Click(object sender, EventArgs e)
{
string url = "https://www.donationalerts.com/r/nik33105";
try
{
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show("Íå óäàëîñü îòêðûòü ññûëêó: " + ex.Message);
}
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
}
}
}