WAV Player

Програма Звуки Windows дає змогу прослухати звукові файли (форматів WAV, RMI та MID), що знаходяться у каталозі Windows\Media Список файлів формується на початку роботи програми. Якщо перемикач безперервно вибрано, то після відтворення поточного файлу автоматично активізується відтворення наступного.

Код написання програми

TForm1 *Form1;
AnsiString SoundPath;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
char *wd;
wd = (char*)AllocMem(MAX_PATH);
GetWindowsDirectoryA(wd,MAX_PATH);
SoundPath = wd;
SoundPath = SoundPath + "\\Media\\";
TSearchRec sr;
if (FindFirst (SoundPath + "*.wav", faAnyFile, sr) == 0)
{
ListBox1->Items->Add(sr.Name);
while (FindNext(sr) == 0 )
ListBox1->Items->Add(sr.Name);
}
if (FindFirst (SoundPath + ".mid", faAnyFile, sr) == 0)
{
ListBox1->Items->Add(sr.Name);
while (FindNext(sr) == 0)
ListBox1->Items->Add(sr.Name);
}
if (FindFirst (SoundPath +".rmi", faAnyFile,sr) == 0)
{
ListBox1->Items->Add(sr.Name);
while (FindNext(sr) == 0)
ListBox1->Items->Add(sr.Name);
}
if (ListBox1->Items->Count != 0)
{
Label2->Caption = ListBox1->Items->Strings[1];
ListBox1->ItemIndex = 0;
MediaPlayer1->FileName = SoundPath + ListBox1->Items->Strings[1];
MediaPlayer1->Open();
MediaPlayer1->Play();
}
}
void __fastcall TForm1::ListBox1Click(TObject *Sender)
{
if ( (CheckBox1->Checked) &&
( MediaPlayer1->Mode == mpPlaying ) )
return;
Label2->Caption = ListBox1->Items->Strings[ListBox1->ItemIndex];
MediaPlayer1->FileName = SoundPath + Label2->Caption;
MediaPlayer1->Open();
if (!CheckBox1->Checked)
MediaPlayer1->Notify = false;
MediaPlayer1->Play();
}
void __fastcall TForm1::MediaPlayer1Notify(TObject *Sender)
{
if ( ListBox1->ItemIndex < ListBox1->Items->Count )
{
ListBox1->ItemIndex = ListBox1->ItemIndex+ 1;
Label2->Caption = ListBox1->Items->Strings[ListBox1->ItemIndex];
MediaPlayer1->FileName = SoundPath + Label2->Caption;
MediaPlayer1->Open();
if ( ! CheckBox1->Checked)
MediaPlayer1->Notify = false;
MediaPlayer1->Play();
}
}

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *