Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Notify Handler is not call when TMediaPlayer.Open() Exception



Permlink Replies: 2 - Last Post: Aug 31, 2016 4:33 PM Last Post By: chen zero
chen zero

Posts: 30
Registered: 5/26/00
Notify Handler is not call when TMediaPlayer.Open() Exception
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2016 8:57 AM
Hello,
A question about usage of TMediaPlayer component.
in normal, when TMediaPlayer open a good wav file, the Notify Handler will be called.
however, when TMediaPlayer open a corrupted wav file, the Notify Handler will NOT be called.

but from doc, TMediaPlayer.NotifyValue can be failure. this seems not consistent.
this inconsistence caused that need to handle error in two places.
if TMediaPlayer also called Notify Handler when error, so, only 1 place need to handle error, that will make more neat.

I posted a demo project in:

https://forums.embarcadero.com/thread.jspa?threadID=229281&tstart=0

env:
C++Builder XE winxp

Thanks!

Edited by: chen zero on Aug 31, 2016 9:00 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Notify Handler is not call when TMediaPlayer.Open() Exception [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2016 12:57 PM   in response to: chen zero in response to: chen zero
chen wrote:

in normal, when TMediaPlayer open a good wav file, the Notify
Handler will be called.
however, when TMediaPlayer open a corrupted wav file, the
Notify Handler will NOT be called.

Of course not. Why would it? The file could not be opened, so it does not
exist within the multimedia system, so it cannot send notifications about
the file. Open() will raise an EMCIDeviceError exception instead.

but from doc, TMediaPlayer.NotifyValue can be failure.

Yes, but the OnNotify event only makes sense for asynchronous commands, like
playback. It does not make sense for synchronous operations, like opening
a file.

The OnNotify event is triggered when TMediaPlayer receives a MM_MCINOTIFY
window message:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd757358.aspx

That message is not issued if the MCI_OPEN command fails:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd743441.aspx

this seems not consistent.

Take it up with Microsoft, they designed the multimedia API that TMediaPlayer
uses internally.

this inconsistence caused that need to handle error in two places.

Not really, if you design your code to separate your UI logic from your business
logic, like you should be. Write a separate function that handles MediaPlayer
notifications, and then have the OnNotify handler call that function. If
Open() fails, call the same function. For example:

void __fastcall TForm9::Button1Click(TObject *Sender)
{
    MediaPlayer1->FileName = "some_corrupted_wav_file.wav";
    MediaPlayer1->Notify = true;
 
    try {
        MediaPlayer1->Open();
    }
    catch (const Exception &) {
        HandleMediaPlayerNotify(nvFailure);
    }
}
 
void __fastcall TForm9::MediaPlayer1Notify(TObject *Sender)
{
    HandleMediaPlayerNotify(MediaPlayer1->NotifyValue);
}
 
void __fastcall TForm9::HandleMediaPlayerNotify(TMPNotifyValues Value)
{
    Memo1->Lines->Add("notify ...." + IntToStr((int)Value));
}


--
Remy Lebeau (TeamB)
chen zero

Posts: 30
Registered: 5/26/00
Re: Notify Handler is not call when TMediaPlayer.Open() Exception [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2016 4:33 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
....
I got the point, thank you very much !
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02