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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
| using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using Un4seen.Bass;
namespace ShadowMediaPlayer
{
public class Program
{
static void Main()
{
IniFile Configurations = new IniFile();
string[] args = Environment.GetCommandLineArgs();
if(args[1].Length <= 0)
{
// Application.Run(new MainForm(Configurations.Read("Track", "Path")));
MessageBox.Show(Configurations.Read("Track", "Path"));
}
else
{
Application.Run(new MainForm(args[1]));
}
}
}
public class MainForm : Form
{
private IniFile Configurations = new IniFile();
private string AppName = "Shadow media player";
private string AppVersion = Application.ProductVersion.ToString();
private string FileName;
private int Stream;
private double FilePosition;
private double FileTime;
private float FileVolume = 1f;
private bool IsPlaying = false;
private bool Paused = false;
private bool Stoped = false;
private bool IsShow = true;
private Button playButton = new Button();
private Button pauseButton = new Button();
private Button stopButton = new Button();
private Button lastTrackButton = new Button();
private Button nextTrackButton = new Button();
private Button minusPositionButton = new Button();
private Button plusPositionButton = new Button();
private Button minusVolumeButton = new Button();
private Button plusVolumeButton = new Button();
private Button exitButton = new Button();
private Button trayButton = new Button();
private Button helpButton = new Button();
private NotifyIcon Tray = new NotifyIcon();
private ContextMenu contextMenu = new ContextMenu();
private MenuItem MenuItem1 = new MenuItem();
private MenuItem MenuItem2 = new MenuItem();
private MenuItem MenuItem3 = new MenuItem();
private const int WM_HOTKEY = 0x0312;
private const int NOMOD = 0x0000;
private const int ALT = 0x0001;
private const int CTRL = 0x0002;
private const int SHIFT = 0x0004;
private const int WIN = 0x0008;
[DllImport("user32.dll")]
public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
public MainForm(string arg)
{
if(!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle))
{
DialogResult result = MessageBox.Show("Не удалось инициализировать устройство воспроизведения.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
if(result == DialogResult.OK)
{
if(Process.GetProcessesByName("Smp").Length > 0)
{
foreach (var process in Process.GetProcessesByName("Smp"))
{
process.Kill();
}
}
}
}
else
{
FileName = arg;
RegisterHotKey(this.Handle, 0, CTRL, (int)Keys.D1);
RegisterHotKey(this.Handle, 1, CTRL, (int)Keys.D2);
RegisterHotKey(this.Handle, 2, CTRL, (int)Keys.D3);
RegisterHotKey(this.Handle, 3, CTRL, (int)Keys.D4);
RegisterHotKey(this.Handle, 4, CTRL, (int)Keys.D5);
RegisterHotKey(this.Handle, 5, CTRL, (int)Keys.D6);
RegisterHotKey(this.Handle, 6, CTRL, (int)Keys.D7);
RegisterHotKey(this.Handle, 7, CTRL, (int)Keys.D8);
RegisterHotKey(this.Handle, 8, CTRL, (int)Keys.D9);
RegisterHotKey(this.Handle, 9, CTRL, (int)Keys.D0);
RegisterHotKey(this.Handle, 10, CTRL + ALT, (int)Keys.D1);
RegisterHotKey(this.Handle, 11, CTRL, (int)Keys.F1);
InitConfigurations();
InitTray();
InitButtons();
InitMainForm();
}
}
private void InitConfigurations()
{
}
private void InitTray()
{
Icon TrayIcon = new Icon(@"Smp.ico");
Tray.Icon = TrayIcon;
Tray.Visible = true;
Tray.Text = AppName + " " + AppVersion;
Tray.ContextMenu = contextMenu;
contextMenu.MenuItems.AddRange(new MenuItem[]{MenuItem1});
MenuItem1.Index = 0;
MenuItem1.Text = "&Показать";
MenuItem1.Click += MenuItem1_Click;
contextMenu.MenuItems.AddRange(new MenuItem[]{MenuItem2});
MenuItem2.Index = 1;
MenuItem2.Text = "&О программе";
MenuItem2.Click += MenuItem2_Click;
contextMenu.MenuItems.AddRange(new MenuItem[]{MenuItem3});
MenuItem3.Index = 2;
MenuItem3.Text = "&Выход";
MenuItem3.Click += MenuItem3_Click;
}
private void InitButtons()
{
this.playButton.Location = new Point(10, 10);
this.playButton.Size = new Size(110, 20);
this.playButton.Text = "Play/RePlay";
this.playButton.Click += playButton_Click;
this.pauseButton.Location = new Point(10, 40);
this.pauseButton.Size = new Size(50, 20);
this.pauseButton.Text = "Pause/Play";
this.pauseButton.Click += pauseButton_Click;
this.stopButton.Location = new Point(70, 40);
this.stopButton.Size = new Size(50, 20);
this.stopButton.Text = "Stop";
this.stopButton.Click += stopButton_Click;
this.lastTrackButton.Location = new Point(10, 70);
this.lastTrackButton.Size = new Size(50, 20);
this.lastTrackButton.Text = "Предыдущий трек";
this.lastTrackButton.Click += lastTrackButton_Click;
this.nextTrackButton.Location = new Point(70, 70);
this.nextTrackButton.Size = new Size(50, 20);
this.nextTrackButton.Text = "Следующий трек";
this.nextTrackButton.Click += nextTrackButton_Click;
this.minusPositionButton.Location = new Point(10, 100);
this.minusPositionButton.Size = new Size(50, 20);
this.minusPositionButton.Text = "-5 секунд";
this.minusPositionButton.Click += minusPositionButton_Click;
this.plusPositionButton.Location = new Point(70, 100);
this.plusPositionButton.Size = new Size(50, 20);
this.plusPositionButton.Text = "+5 секунд";
this.plusPositionButton.Click += plusPositionButton_Click;
this.minusVolumeButton.Location = new Point(10, 130);
this.minusVolumeButton.Size = new Size(50, 20);
this.minusVolumeButton.Text = "Тише";
this.minusVolumeButton.Click += minusVolumeButton_Click;
this.plusVolumeButton.Location = new Point(70, 130);
this.plusVolumeButton.Size = new Size(50, 20);
this.plusVolumeButton.Text = "Громче";
this.plusVolumeButton.Click += plusVolumeButton_Click;
this.exitButton.Location = new Point(10, 160);
this.exitButton.Size = new Size(50, 20);
this.exitButton.Text = "Выход";
this.exitButton.Click += exitButton_Click;
this.trayButton.Location = new Point(70, 160);
this.trayButton.Size = new Size(50, 20);
this.trayButton.Text = "Tray";
this.trayButton.Click += trayButton_Click;
this.helpButton.Location = new Point(10, 190);
this.helpButton.Size = new Size(110, 20);
this.helpButton.Text = "О программе";
this.helpButton.Click += helpButton_Click;
}
private void InitMainForm()
{
this.ClientSize = new Size(130, 220);
this.Name = "MainForm";
this.Text = AppName + " " + AppVersion;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Controls.AddRange(new Control[]{playButton, pauseButton, stopButton, lastTrackButton, nextTrackButton, minusPositionButton, plusPositionButton, minusVolumeButton, plusVolumeButton, exitButton, trayButton, helpButton});
this.Load += MainForm_Load;
this.FormClosing += MainForm_Close;
}
private void MainForm_Load(object sender, EventArgs e)
{
Play();
}
private void playButton_Click(object sender, EventArgs e)
{
Play();
}
private void pauseButton_Click(object sender, EventArgs e)
{
Pause();
}
private void stopButton_Click(object sender, EventArgs e)
{
Stop();
}
private void lastTrackButton_Click(object sender, EventArgs e)
{
// LastTrack();
}
private void nextTrackButton_Click(object sender, EventArgs e)
{
// NextTrack();
}
private void minusPositionButton_Click(object sender, EventArgs e)
{
MinusPosition();
}
private void plusPositionButton_Click(object sender, EventArgs e)
{
PlusPosition();
}
private void minusVolumeButton_Click(object sender, EventArgs e)
{
MinusVolume();
}
private void plusVolumeButton_Click(object sender, EventArgs e)
{
PlusVolume();
}
private void exitButton_Click(object sender, EventArgs e)
{
Exit();
}
private void trayButton_Click(object sender, EventArgs e)
{
ShowWindow();
}
private void helpButton_Click(object sender, EventArgs e)
{
Help();
}
private void MenuItem1_Click(object Sender, EventArgs e)
{
ShowWindow();
}
private void MenuItem2_Click(object Sender, EventArgs e)
{
Help();
}
private void MenuItem3_Click(object Sender, EventArgs e)
{
Exit();
}
private void Play()
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_StreamFree(Stream);
Stream = Bass.BASS_StreamCreateFile(FileName, 0, 0, BASSFlag.BASS_DEFAULT);
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, FileVolume);
IsPlaying = true;
Paused = false;
Stoped = false;
Tray.Text = AppName + " " + AppVersion + " (Воспроизводится)";
}
private void Pause()
{
if(Stoped == true)
{
return;
}
if(IsPlaying && !Paused)
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_ChannelPause(Stream);
IsPlaying = false;
Paused = true;
Tray.Text = AppName + " " + AppVersion + " (Пауза)";
}
else
{
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
IsPlaying = true;
Paused = false;
Tray.Text = AppName + " " + AppVersion + " (Воспроизводится)";
}
}
private void Stop()
{
if(IsPlaying)
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_ChannelStop(Stream);
Bass.BASS_StreamFree(Stream);
IsPlaying = false;
Stoped = true;
Tray.Text = AppName + " " + AppVersion + " (Остановлен)";
}
}
/*
private void LastTrack()
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_StreamFree(Stream);
currentIndex = List.SelectedIndex;
currentIndex -= 1;
if(currentIndex < 0)
{
currentIndex += 1;
List.SetSelected(currentIndex, true);
Stream = Bass.BASS_StreamCreateFile("dat\\articles\\" + List.SelectedItem.ToString() + ".wav", 0, 0, BASSFlag.BASS_UNICODE);
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
IsPlaying = true;
Paused = false;
Tray.Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString() + " (Воспроизводится)";
Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString();
}
else
{
List.SetSelected(currentIndex, true);
Stream = Bass.BASS_StreamCreateFile("dat\\articles\\" + List.SelectedItem.ToString() + ".wav", 0, 0, BASSFlag.BASS_UNICODE);
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
IsPlaying = true;
Paused = false;
Tray.Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString() + " (Воспроизводится)";
Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString();
}
}
*/
/*
private void NextTrack()
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_StreamFree(Stream);
currentIndex = List.SelectedIndex;
currentIndex += 1;
if(currentIndex >= List.Items.Count)
{
currentIndex -= 1;
List.SetSelected(currentIndex, true);
Stream = Bass.BASS_StreamCreateFile("dat\\articles\\" + List.SelectedItem.ToString() + ".wav", 0, 0, BASSFlag.BASS_UNICODE);
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
IsPlaying = true;
Paused = false;
Tray.Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString() + " (Воспроизводится)";
Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString();
}
else
{
List.SetSelected(currentIndex, true);
Stream = Bass.BASS_StreamCreateFile("dat\\articles\\" + List.SelectedItem.ToString() + ".wav", 0, 0, BASSFlag.BASS_UNICODE);
Bass.BASS_ChannelPlay(Stream, false);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 500);
IsPlaying = true;
Paused = false;
Tray.Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString() + " (Воспроизводится)";
Text = AppName + " " + AppVersion + " - " + List.SelectedItem.ToString();
}
}
*/
private void MinusPosition()
{
FilePosition = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream));
FilePosition -= 5;
if(FilePosition < 0)
{
return;
}
else
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 250);
Thread.Sleep(250);
Bass.BASS_ChannelSetPosition(Stream, FilePosition);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 250);
Thread.Sleep(250);
}
}
private void PlusPosition()
{
FilePosition = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream));
FileTime = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream));
FilePosition += 5;
if(FilePosition >= FileTime)
{
return;
}
else
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 250);
Thread.Sleep(250);
Bass.BASS_ChannelSetPosition(Stream, FilePosition);
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1F, 250);
Thread.Sleep(250);
}
}
private void MinusVolume()
{
if(FileVolume < 0f)
{
return;
}
else
{
FileVolume -= 0.1f;
Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, FileVolume);
}
}
private void PlusVolume()
{
if(FileVolume >= 1f)
{
return;
}
else
{
FileVolume += 0.1f;
Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, FileVolume);
}
}
private void Exit()
{
WriteConfigurations();
if(Process.GetProcessesByName("Smp").Length > 0)
{
foreach (var process in Process.GetProcessesByName("Smp"))
{
Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 0F, 500);
Thread.Sleep(500);
Bass.BASS_ChannelStop(Stream);
Bass.BASS_StreamFree(Stream);
UnregisterHotKey(this.Handle, 0);
UnregisterHotKey(this.Handle, 1);
UnregisterHotKey(this.Handle, 2);
UnregisterHotKey(this.Handle, 3);
UnregisterHotKey(this.Handle, 4);
UnregisterHotKey(this.Handle, 5);
UnregisterHotKey(this.Handle, 6);
UnregisterHotKey(this.Handle, 7);
UnregisterHotKey(this.Handle, 8);
UnregisterHotKey(this.Handle, 9);
UnregisterHotKey(this.Handle, 10);
UnregisterHotKey(this.Handle, 11);
Tray.Visible = false;
process.Kill();
}
}
}
private void ShowWindow()
{
if(IsShow == true)
{
this.Visible = false;
IsShow = false;
}
else
{
this.Visible = true;
IsShow = true;
}
}
private void Help()
{
MessageBox.Show("Название: " + AppName + "\r\nВерсия: " + AppVersion + "\r\nРазработчик: Владислав Буяльский\r\nДата выпуска: 2018\r\nЯзык: Русский\r\nСтатус: Бесплатная\r\nСистемные требования: Windows all\r\nСайт разработчика: http://www.vlad-mus.ru\r\nE-mail разработчика: admin@vlad-mus.ru\r\n\r\nДополнительную информацию см. в файле Readme.txt\r\n\r\n", "О программе", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void WriteConfigurations()
{
Configurations.Write("Track", "Path", FileName);
Configurations.Write("Track", "FilePosition", Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream)).ToString());
Configurations.Write("Track", "Volume", FileVolume.ToString());
}
private void MainForm_Close(object sender, FormClosingEventArgs e)
{
Exit();
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_HOTKEY:
int modifier = (int)m.LParam & 0xFFFF;
Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
if(modifier == CTRL && key == Keys.D1)
{
SpeachProvider.Speak("Воспроизведение");
Play();
}
else if(modifier == CTRL && key == Keys.D2)
{
SpeachProvider.Speak("Пауза/Воспроизведение");
Pause();
}
else if(modifier == CTRL && key == Keys.D3)
{
SpeachProvider.Speak("Стоп");
Stop();
}
else if(modifier == CTRL && key == Keys.D4)
{
SpeachProvider.Speak("Предыдущий трек");
// LastTrack();
}
else if(modifier == CTRL && key == Keys.D5)
{
SpeachProvider.Speak("Следующий трек");
// NextTrack();
}
else if(modifier == CTRL && key == Keys.D6)
{
SpeachProvider.Speak("-5 секунд");
MinusPosition();
}
else if(modifier == CTRL && key == Keys.D7)
{
SpeachProvider.Speak("+5 секунд");
PlusPosition();
}
else if(modifier == CTRL && key == Keys.D8)
{
SpeachProvider.Speak("Тише");
MinusVolume();
}
else if(modifier == CTRL && key == Keys.D9)
{
SpeachProvider.Speak("Громче");
PlusVolume();
}
else if(modifier == CTRL && key == Keys.D0)
{
SpeachProvider.Speak("Выход");
Exit();
}
else if(modifier == CTRL + ALT && key == Keys.D1)
{
ShowWindow();
}
else if(modifier == CTRL && key == Keys.F1)
{
Help();
}
break;
}
base.WndProc(ref m);
}
}
} |