-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSound.cpp
More file actions
141 lines (121 loc) · 3.2 KB
/
Sound.cpp
File metadata and controls
141 lines (121 loc) · 3.2 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
/*
Open source not for commercial deployment
*/
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Sound.h"
#include "GlobalUnit.h"
void TMainForm::SetPlayButtonForNewSong()
{
if ( checkSongFile(PreviewSongData.fileName))
{
ButtonPlay->Visible = true;
}
ButtonStop->Visible = ButtonPause->Visible;
}
void __fastcall TMainForm::ButtonPlayClick(TObject *Sender)
{
bool FileFound=false;
String s = PreviewSongData.fileName;
// if (s.Pos(":")==0) s = BaseDir + s;
{
s = replace(s,".txt", ".mp3");
ifstream songfile(s.c_str());
if (songfile.is_open())
{
FileFound=true;
songfile.close();
}
}
if (!FileFound)
{
s = replace(s, ".mp3", ".mid");
ifstream songfile(s.c_str());
if (songfile.is_open())
{
FileFound=true;
songfile.close();
}
}
if (FileFound)
{
if (MediaPlayer->FileName != s)
{
MediaPlayer->FileName = s;
MediaPlayer->Open();
}
ButtonPlay->Visible=false;
ButtonPause->Visible=true;
ButtonStop->Visible=true;
MediaPlayer->Play();
}
MediaPlayer->Notify=true;
loopMusic=true;
BlockFocus=false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ButtonEnter(TObject *Sender)
{
BlockFocus=true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ButtonPauseClick(TObject *Sender)
{
loopMusic=false;
if (ButtonPlay->Visible)
ButtonStop->Visible=false;
else
ButtonStop->Visible = checkSongFile(PreviewSongData.fileName);
ButtonPause->Visible=false;
ButtonPlay->Visible= checkSongFile(PreviewSongData.fileName);
MediaPlayer->Pause();
BlockFocus=false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ButtonStopClick(TObject *Sender)
{
loopMusic=false;
ButtonStop->Visible=false;
ButtonPause->Visible=false;
ButtonPlay->Visible= checkSongFile(PreviewSongData.fileName);
MediaPlayer->FileName = "";
MediaPlayer->Stop();
BlockFocus=false;
}
//---------------------------------------------------------------------------
bool TMainForm::checkSongFile(String s)
{
s = replace(s,".txt", ".mp3");
{
ifstream songfile(s.c_str());
if (songfile.is_open())
{
songfile.close();
return true;
}
}
s = replace(s, ".mp3", ".mid");
{
ifstream songfile(s.c_str());
if (songfile.is_open())
{
songfile.close();
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MediaPlayerNotify(TObject *Sender)
{
/* if (MediaPlayer->NotifyValue == nvSuccessful)
if (loopMusic)
{
MediaPlayer->Play();
MediaPlayer->Notify=true;
}
*/
TMainForm::ButtonStopClick(Sender);
}
//---------------------------------------------------------------------------
#pragma package(smart_init)