www.pudn.com > SingleNumber.rar > Unit2.cpp
//--------------------------------------------------------------------------- #include#pragma hdrstop #include "Unit2.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; String str,str1=""; AnsiString str2; int p,q,kz=0,mu=-1,x=0,v=0,z=0; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm2::Button1Click(TObject *Sender) { AnsiString MyFilename; OpenDialog1->Options.Clear(); OpenDialog1->Options << ofAllowMultiSelect << ofFileMustExist; if(this->OpenDialog1->Execute()) { this->MediaPlayer1->FileName=""; this->MediaPlayer1->FileName=this->OpenDialog1->FileName; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->Label3->Caption="☆"+this->OpenDialog1->FileName+"☆"; } this->ListBox2->Items->AddStrings(this->OpenDialog1->Files); this->ListBox1->Items->Clear(); for(int i=0;i ListBox2->Count;i++) { str=this->ListBox2->Items->Strings[i]; MyFilename=ExtractFileName(str); this->ListBox1->Items->Add(MyFilename); } this->Label3->Visible=true; this->Label1->Visible=true; if(this->ListBox1->Count!=-1)this->ListBox1->ItemIndex=0; this->Label1->Caption=this->MediaPlayer1->Position; this->ListBox2->ItemIndex=this->ListBox1->ItemIndex; TrackBar1->Min=0; TrackBar1->Position=0; TrackBar1->Max=MediaPlayer1->Length; } //--------------------------------------------------------------------------- void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action) { Action=caFree; } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer3Timer(TObject *Sender) { TrackBar1->Position=MediaPlayer1->Position; } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer2Timer(TObject *Sender) { static a; if(this->Label3->Left+this->Label3->Width>335) { a=0; } if(this->Label3->Left<0) { a=1; } if(a==1) { this->Label3->Left=this->Label3->Left+10; } else { this->Label3->Left=this->Label3->Left-10; } } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer1Timer(TObject *Sender) { int f,m; if(this->ListBox1->ItemIndex!=-1) { f=(this->MediaPlayer1->Length-this->MediaPlayer1->Position)/1000/60; m=(this->MediaPlayer1->Length-this->MediaPlayer1->Position)/1000%60; this->Label1->Caption=f; this->Label1->Caption="☆"+this->Label1->Caption+":"; if(m<10) { this->Label1->Caption=this->Label1->Caption+"0"; this->Label1->Caption=this->Label1->Caption+m+"☆ "; } else this->Label1->Caption=this->Label1->Caption+m+"☆ "; } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button3Click(TObject *Sender) { try { kz=kz%3; if(this->Button3->Caption=="随机播放"&&kz==2) { this->Button3->Caption="单曲循环"; } if(this->Button3->Caption=="单曲循环"&&kz==0) { this->Button3->Caption="循环播放"; } if(this->Button3->Caption=="循环播放"&&kz==1) { this->Button3->Caption="随机播放"; } kz++; mu=this->ListBox1->ItemIndex; } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button2Click(TObject *Sender) { try { del=1; this->MediaPlayer1->Stop(); this->ListBox2->Items->Delete(this->ListBox1->ItemIndex); this->ListBox1->Items->Delete(this->ListBox1->ItemIndex); if(this->ListBox1->Items->Count-1==this->ListBox1->ItemIndex) { this->ListBox1->ItemIndex=0; this->ListBox2->ItemIndex=0; this->MediaPlayer1->Stop(); } else { this->ListBox1->ItemIndex=this->ListBox1->ItemIndex+1; this->ListBox2->ItemIndex=this->ListBox2->ItemIndex+1; this->MediaPlayer1->Stop(); } //this->MediaPlayer1->FileName=this->ListBox2->Items->Strings[0]; //this->MediaPlayer1->Play(); musicd++; //ShowMessage(this->MediaPlayer1->FileName); } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button4Click(TObject *Sender) { try { this->MediaPlayer1->Pause(); if(this->Button4->Caption=="暂停") { this->Button4->Caption="播放"; } else this->Button4->Caption="暂停"; } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button7Click(TObject *Sender) { try { String ss,ss2; this->ListBox1->ItemIndex=0; this->ListBox2->ItemIndex=0; ss=this->ListBox1->Items->Strings[0]; ss2=this->ListBox2->Items->Strings[0]; this->MediaPlayer1->FileName=ss; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->Label3->Caption="☆"+ss2+"☆ "; TrackBar1->Min=0; TrackBar1->Position=0; TrackBar1->Max=MediaPlayer1->Length; } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button8Click(TObject *Sender) { try { int nn=this->ListBox1->ItemIndex; int nn2=this->ListBox2->ItemIndex; AnsiString ss,ss2; if((nn<0)||(nn>=(this->ListBox1->Items->Count-1))) return; if((nn2<0)||(nn2>=(this->ListBox2->Items->Count-1))) return; this->ListBox1->ItemIndex=nn+1; this->ListBox2->ItemIndex=nn2+1; ss=this->ListBox1->Items->Strings[nn+1]; ss2=this->ListBox2->Items->Strings[nn2+1]; this->MediaPlayer1->FileName=ss; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->MediaPlayer1->Eject(); this->Label3->Caption="☆"+ss2+"☆ "; TrackBar1->Min=0; TrackBar1->Position=0; TrackBar1->Max=MediaPlayer1->Length; } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Button9Click(TObject *Sender) { try { String ss,ss2; if(del==1) { this->ListBox1->ItemIndex=musicd-1; this->ListBox2->ItemIndex=musicd-1; } else { this->ListBox1->ItemIndex=musicn-1; this->ListBox2->ItemIndex=musicn-1; } ss=this->ListBox1->Items->Strings[this->ListBox1->Count-1]; ss2=this->ListBox2->Items->Strings[this->ListBox2->Count-1]; this->MediaPlayer1->FileName=ss; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->ListBox1->ItemIndex=this->ListBox1->Count-1; this->ListBox2->ItemIndex=this->ListBox2->Count-1; this->Label3->Caption="☆"+ss2+"☆ "; //ShowMessage(this->ListBox2->Items->Strings[this->ListBox2->Count-1]); TrackBar1->Min=0; TrackBar1->Position=0; TrackBar1->Max=MediaPlayer1->Length; } catch(...) { } } //--------------------------------------------------------------------------- void __fastcall TForm2::Edit1Change(TObject *Sender) { int ii,st; AnsiString ss; ss=this->Edit1->Text.Trim(); //去掉里面的空格 ii=SendMessage(this->ListBox1->Handle,LB_FINDSTRING,0,long(ss.c_str())); //查找匹配字符串,忽略大小写,从指定开始表项序号开始查找,当查到某表项的文本字符串的前面包括指定的字符串则结束,找不到则转到列表框第一项继续查找,直到查完所有表项,如果wParam为-1则从列表框第一项开始查找,如果找到则返回表项序号,否则返回LB_ERR。如:表项字符串为"abc123"和指定字串"ABC"就算匹配。; if(ii!=LB_ERR) //LB_ERR表代着是-1 { this->ListBox1->ItemIndex=ii; } } //--------------------------------------------------------------------------- void __fastcall TForm2::ListBox1Click(TObject *Sender) { this->ListBox2->ItemIndex=this->ListBox1->ItemIndex; } //--------------------------------------------------------------------------- void __fastcall TForm2::ListBox1DblClick(TObject *Sender) { str=""; this->MediaPlayer1->FileName=""; str=this->ListBox2->Items->Strings[this->ListBox1->ItemIndex]; this->Label3->Caption="☆"+this->ListBox2->Items->Strings[this->ListBox1->ItemIndex]+"☆ "; mu=this->ListBox1->ItemIndex; this->MediaPlayer1->FileName=str; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); } //--------------------------------------------------------------------------- void __fastcall TForm2::MediaPlayer1Notify(TObject *Sender) { int sui; int a=this->ListBox1->Items->Count; if(this->MediaPlayer1->Position==this->MediaPlayer1->Length && this->Button3->Caption=="单曲循环") { this->MediaPlayer1->Play(); } if(this->MediaPlayer1->Position==this->MediaPlayer1->Length && this->Button3->Caption=="循环播放") { if(this->ListBox1->ItemIndex==-1&&this->ListBox2->ItemIndex==-1&&mu==-1)mu=0; if(mu==a)mu=0; str=this->ListBox2->Items->Strings[mu]; this->Label3->Caption="☆"+str+"☆ "; this->MediaPlayer1->FileName=""; this->MediaPlayer1->FileName=str; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->ListBox1->ItemIndex=mu; mu++; } if(this->MediaPlayer1->Position==this->MediaPlayer1->Length && this->Button3->Caption=="随机播放") { sui=random(a); this->MediaPlayer1->FileName=""; str=this->ListBox2->Items->Strings[sui]; this->Label3->Caption="☆"+str+"☆ "; this->MediaPlayer1->FileName=str; this->MediaPlayer1->Open(); this->MediaPlayer1->Play(); this->ListBox1->ItemIndex=sui; } this->Label1->Caption=this->MediaPlayer1->Position; TrackBar1->Min=0; TrackBar1->Position=0; TrackBar1->Max=MediaPlayer1->Length; } //---------------------------------------------------------------------------