Re: mediaplayer problems

Posted by DelphiMan

In Reply to mediaplayer problems posted by Bo Johansson

: I have a button and a mediaplayer on a form.
: The button have this code (not the mediaplayer button):
:
: procedure TForm1.Button1Click(Sender: TObject);
: begin
: MediaPlayer1.Open;
: MediaPlayer1.FileName:='F:\Min musik\Tractionprojekt\cd_a511040e_trk03.wav';
: MediaPlayer1.Play;
: end;
: Nothing happens, nor errors. But if set it up like this:
: 1. Chose another file in the filename property of the mediaplayer.
: 2. Click the button.
: Now this file plays.

: What shall I do in order to play this file the first time. I guess it has something to do with the filename but I don't know what.

In Delphi's Help, you find the following about the property FileName of TMediaPlayer:

"FileName specifies the media file to be opened by the Open method, or the file to save by the Save method."
This indicates that you have to set FileName *before* you use MediaPlayer.Open :)

So, change the sequence in your source code to:

procedure TForm1.Button1Click(Sender: TObject);
begin
  MediaPlayer1.FileName:='F:\Min musik\Tractionprojekt\cd_a511040e_trk03.wav';
  MediaPlayer1.Open;
  MediaPlayer1.Play;
end;

Follow Ups