Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't change Filename in MediaPlayer

Status
Not open for further replies.

abrogard

Technical User
Sep 13, 2002
58
AU

I'm trying to use a media player on a form to play a small .wav file - I want to change the file that gets played according to user input.

The programme compiles and runs okay but the player doesn't recognise my changes of filename and always plays the filename I entered on the object inspector.

If I don't enter anything in the object inspector then it plays nothing.

It was originally in a case thing but now I'm trying to get it to just accept one coded filename and play it and it won't do it.

Any clues, anyone? :)

 
juust stuck this together and it works oK

od is an open dialog
mp is a media player
are you sure you are including the full path to the wav file

procedure TForm1.Button1Click(Sender: TObject);
begin
with od do
if execute then
mp.FileName := filename

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
mp.open;
mp.Play;
end;


Steve
Be excellent to each other and Party on!
 
thanks sg, I'll try it. My setup is a tad different - I don't have any dialogues, any buttons. I'm catching the keypress and according to the keypressed I'm displaying an image (this is a little prog for little kids). That all works fine. then I thought I'd play a sound with each image and that's when it stopped working. Change the soundfile according to their keypresses same as the images.

Yes, I'm sure I've got the right path. I put the test file in root c:\ to ensure that.

You could say that what you've got there I've already got (minus the od stuff) and it works alright but just doesn't accept my changes of filename.

I was thinking perhaps there was something 'hard coded' in the object thing perhaps blocking the code from changing the filename... but nothing I change seems to do it...

If you've got any further thoughts... any troubleshooting routine perhaps... please let me know... I'm virtually a total beginner on delphi

:)
 
You can check the filename is what you think it is
edit1.text := MP.filename;

Tere are some other approachs you could take that might get round it.
1. Create an instance of TMediaPlayer as you need it e.g.

var MP: TMediaPlayer;
procedure TForm1.Button3Click(Sender: TObject);
begin
MP := tmediaplayer.Create(application);
mp.parent := form1;
end;

and free each one when it has finished;

2. Dont use mediaplayer but play the wav file directly using an API function 'Playsound' or simular there have been some recent threads on this subject.




Steve
Be excellent to each other and Party on!
 
Thank you Steve. I'll try all you suggest.

I like that last suggestion best - use a playsound function - I wanted to do that and I searched Delphi Help for 'sound' and 'play' and whatever I could think of and got nothing pointing me to that. Now I've got the word 'playsound' I'll try again and I'll look for the threads you mention. Seems to me to be much the better way.. I don't need a player on the form at all, it's overkill.

But I'm very interestd in why it isn't working for me and I'll keep trying to find out exactly what's hanging it up.

Talking help but off the topic here I've got VB6 and no help screens - tells me MSDN isn't installed. I haven't got MSDN and don't know how to get it bar going to a shop and trying to buy it - but why do I need that when all I want is help with my VB6?

Bad form that, chaining topics, etc., sorry, won't do it again. :)

I'll tell you if I get it working. Thanks again. ab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top