Article View: borland.public.cppbuilder.multimedia
Article #677Re: Media Player with .wav files
From: Marcelo R. Lopez, Jr.
Date: Tue, 15 Apr 2003 14:42
Date: Tue, 15 Apr 2003 14:42
126 lines
5141 bytes
5141 bytes
Things to remember when using TMediaPlayer ( trust me on this )
1. Don't Auto Open the Device. Only open it when you're going to play, and
when you're notified that it's done ( i.e. mpStopped )...close it until you
need it again.
2. Assign the file first, then Open(), then Play(). Got it ?
3. If you want to switch file names. Close(), Assign, Open(), Play()
Think of it as a telephone without three way calling. You're on a phone
call, but you want to make another call. You've got to hang up first.Then
dial the new number.
Also.....unless you really need the UI controls to TMediaPlayer...consider
looking in a little spoken of, and lesser known header file called,
MMSYSTEM.H. Then using something like this:
char szBuffer[512];
DWORD dwErr = mciSendString ( "open filename.whatever device waveaudio
wait", szBuffer, 511, NULL );
if ( dwErr == 0 )
mciSendString ( "play waveaudio wait", szBuffer, 511, NULL );
if ( dwErr == 0 )
mciSendString ( "close waveaudio wait", szBuffer, 511, NULL );
This will do the same thing as "PlaySound" essentially, except my example
will play it synchronously. If you wanted to do it asynchronously, then
substitute "notify" instead of the "wait" in the "play" command, as well as
pass a window handle. Capture the MM_MCINOTIFY message in a WndProc ( yes,
you'd have to override it ), and then in the notify, perform your "close"
command.
Marcelo R. Lopez, Jr.
"Prof. Chuck Kelly" <ckelly@monroeccc.edu> wrote in message
news:3e823b59$1@newsgroups.borland.com...
>
> "Steve McKewen" <stevemckewen@bigpond.com.au> wrote:
> >I had an app written some time ago in V4 ro V5 that used a media player
to
> >play assorted wav files, but now I can't do it.
> >
> >I have a media player component , that I want to assign .wav files to the
> >FileName property programmatically, and then play them using a call to
> >MediaPlayer1->Play().
> >
> >Its not working but.
> >If I assign the FileName at design time, then I can play that file, but
once
> >I reassign the FileName it doesn't work anymmore.
> >
> >
> >I click btnBrowse and it preloads an OpenDialog with the current filename
> >and on completion write the new filename back to a editbox (eAudioFile)
> >
>
>//-------------------------------------------------------------------------
-
> >-
> >void __fastcall TAlarmOptions::btnBrowseClick(TObject *Sender)
> >{
> > //Use the open file dialog ODSounds
> > //Load the filename with the current value
> > ODSounds->FileName = eAudioFile->Text;
> > //Show the dialog
> > if (ODSounds->Execute())
> > {
> > //Save the filename selected to the alarm option
> > eAudioFile->Text = ODSounds->FileName;
> > }
> >}
> >
> >When eAudioFile is changed it copies its text into the media player
> >MPAudioFile FileName property.
> >
>
>//-------------------------------------------------------------------------
-
> >-
> >void __fastcall TAlarmOptions::eAudioFileChange(TObject *Sender)
> >{
> > //Setup the media player
> > MPAudioFile->FileName = eAudioFile->Text;
> >}
> >
> >When you clik the play button it should play
> >
>
>//-------------------------------------------------------------------------
-
> >-
> >void __fastcall TAlarmOptions::TestClick(TObject *Sender)
> >{
> > MPAudioFile->Notify = true;
> > MPAudioFile->Wait = true;
> > MPAudioFile->Play();
> >}
> >
> >but it doesn't
> >
> >The Media Player is set up like this at design time.
> >
> >AutoOpen = true
> >AutoEnable = true
> >AutoRewind = true
> >DeviceType = dtWaveAudio
> >Enabled = true
> >FileName = ""
> >Shareable = true
> >
> >Any help would be greatly appreciated.
> >
> >
>
> How about using PlaySound to play the sounds. Builder's help contains more
info.
>
> #include <vcl\mmsystem.hpp> // must have this for PlaySound() to work
>
> if (FileExists(AnsiString(fileName))) {
> PlaySound(fileName, NULL,
> SND_ASYNC | SND_NOSTOP | SND_FILENAME);
>
>
Technical Details
Message-ID:
<3e9c18cf@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3e6143b5@newsgroups.borland.com> <3e823b59$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d0fc,d2d1de8fa03921dc X-Google-Attributes: gid10d0fc,public X-Google-ArrivalTime: 2003-04-15 07:40:35 PST Reply-To: "Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> From: "Marcelo R. Lopez, Jr." <marcelol@directvinternet.com> Newsgroups: borland.public.cppbuilder.multimedia References: <3e6143b5@newsgroups.borland.com> <3e823b59$1@newsgroups.borland.com> Subject: Re: Media Player with .wav files Date: Tue, 15 Apr 2003 10:42:07 -0400 Lines: 128 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 64.221.40.13 Message-ID: <3e9c18cf@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1050417359 64.221.40.13 (15 Apr 2003 07:35:59 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail