Board index » cppbuilder » TMediaPlayer plays a loop
Doug Vanderwater
![]() CBuilder Developer |
TMediaPlayer plays a loop2006-07-04 05:24:49 AM cppbuilder62 First the good news: There is a main form containing a List Box which displays a list of music files using TMediaPlayer. The main form also contains needed buttons to control the media player each with its own code. The player works properly , playing the music using a loop coded as follows: void __fastcall TForm1::StartBtnClick(TObject *Sender) { int NumLines = MusicList->Items->Count; // various other declarations int i = 0; MusicList->ItemIndex = i; // loops through the lines in the music file for(;i < NumLines; i++) { // a series of if statements for cut copy and paste operations MusicProgramLine = MusicList->Iems->Strings[i]; // Method to extract the music file name and path from the music file line MusicPath = GetMusFilNam(MusicProgramLine); if(FileExists(MusicPath)) { MediaPlayer1->FileName = MusicPath; MediaPlayer1->Open( ); // enable the available buttons which control the Media Player UpdateControls( ); MediaPlayer1->Wait = false; MediaPlayer1->Play( ); // set available buttons which may now control the Media Player UpdateControls( ); while (MediaPlayer1->Mode == mpPlaying) { Application->ProcessMessages( ); } } // end of if (File Exists) } // end of for ( ) loop Now for the bad news: In a related MDI program the Main Form contains several MDI pages which list music files of various types ... Tango, Mambo, Cha Cha .. etc. These MDI forms contains a ListBox to display the list. There is also a button to "Play a Selected Line" and a button to "Play the Entire List". "Play a Selected Line" plays the selected line properly. "Play the Entire List" simply loops through the entire list and plays the last item. It acts as if the code "Application->ProcessMessages( );" is not doing its job. The only way to get the entire list to play is to set MediaPlayer1->Wait = false; to read MediaPlayer1 ->Wait = true; which means the MediaPlayer does not return when music is palyed, this disabling player controls such as Stop, Pause.. or other buttons. In stepping through he code, the line "Application->ProcessMessages" appears to execute ..... but I think it is not working. Is there something about MDI forms giving a problem? Some property not set correctly? What has been overlooked here? Happy Dancing! Doug. |