I have a VERY simple application that has three Media Players and takes a wav file and plays it in one of the three Media Players. Can someone tell me how to get the OnNotify event handler to work in a better way so that when the file stops playing and the Notify is called, the status of the Media Player will be Stopped and not still Playing. I have tried to use the Wait property but I seem to be doing it wrong. I am using the TMediaPlayer like this:
Player->FileName = filename;
Player->Close();
Player->Open();
Player->Play();
My application has an Edit Box for the filename and an edit box for the status of the device (playing, paused, stopped etc.)
From my reading about the Media Player, the Notify function should be called when the state changes. I see it begin called when I stope through it but for some reason when the file stops and the Notify is called, the status of the file is still listed as "Playing" and not "Stopped" so the status Edut Box on my application doesn't clear out and say "Stopped"
Below is my OnNotify Event Handler:
TMediaPlayer *player;
TEdit *status;
TEdit *device;
for(int i = 0; i < Players->Count; i++)
{
player = (TMediaPlayer*) Players->Items;
if(player == Sender)
{
status = (TEdit*) Status->Items;
device = (TEdit*) Devices->Items;
switch ((int)player->Mode){
case mpStopped :
WriteToLog("Stopped"
player->FileName = "";
player->Close();
status->Text = "Stopped";
device->Text = "";
break;
case mpPlaying :
WriteToLog("Playing"
status->Text = "Playing";
break;
case mpPaused :
WriteToLog("Paused"
status->Text = "Paused";
break;
default :
WriteToLog("Default"
player->FileName = "";
player->Close();
status->Text = "Stopped";
device->Text = "";
break;
}
/* must reset the Notify property to True to be
notified the next time the mode changes */
player->Notify = true;
String message = AnsiString(player->Tag)+ "," + status->Text + "%%";
int connections = ServerSocket->Socket->ActiveConnections;
//StatusBar->SimpleText = message;
WriteToLog("outgoing: " + message);
for(int i = 0; i < connections; i++)
ServerSocket->Socket->Connections->SendText(message);
break;
}
}
}
Player->FileName = filename;
Player->Close();
Player->Open();
Player->Play();
My application has an Edit Box for the filename and an edit box for the status of the device (playing, paused, stopped etc.)
From my reading about the Media Player, the Notify function should be called when the state changes. I see it begin called when I stope through it but for some reason when the file stops and the Notify is called, the status of the file is still listed as "Playing" and not "Stopped" so the status Edut Box on my application doesn't clear out and say "Stopped"
Below is my OnNotify Event Handler:
TMediaPlayer *player;
TEdit *status;
TEdit *device;
for(int i = 0; i < Players->Count; i++)
{
player = (TMediaPlayer*) Players->Items;
if(player == Sender)
{
status = (TEdit*) Status->Items;
device = (TEdit*) Devices->Items;
switch ((int)player->Mode){
case mpStopped :
WriteToLog("Stopped"
player->FileName = "";
player->Close();
status->Text = "Stopped";
device->Text = "";
break;
case mpPlaying :
WriteToLog("Playing"
status->Text = "Playing";
break;
case mpPaused :
WriteToLog("Paused"
status->Text = "Paused";
break;
default :
WriteToLog("Default"
player->FileName = "";
player->Close();
status->Text = "Stopped";
device->Text = "";
break;
}
/* must reset the Notify property to True to be
notified the next time the mode changes */
player->Notify = true;
String message = AnsiString(player->Tag)+ "," + status->Text + "%%";
int connections = ServerSocket->Socket->ActiveConnections;
//StatusBar->SimpleText = message;
WriteToLog("outgoing: " + message);
for(int i = 0; i < connections; i++)
ServerSocket->Socket->Connections->SendText(message);
break;
}
}
}