Solved

multiselect cd-playing

Posted on 2001-06-16
8
234 Views
Last Modified: 2010-04-06
I have a ComboBox where all the cd-rom drives is listed. Now I when the user clicks one of items, the selected drive will start playing an audio cd, if any. I would like to use the TMediaPlayer to this.
0
Comment
Question by:easysoft_studios
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 6201699
What you could try doing is setting the TMediaPlayer's filename property to be the selected drive

e.g.

MediaPlayer1.Filename := 'f:';  //Play the disc in F:
MediaPlayer1.Filename := 'g:';  //Play the disc in G:

Getting the selecton from the ComboBox is pretty simple as long as you keep a list of which entry in the list relates to which drive:

...  //Fill the combobox with your list of drives (which you've already placed in a TStringList using the format '<Drive letter>:')
  ComboBox1.Items.Clear;
  FOR iCount := 0 TO (stlDrives.Count - 1)
  DO
    Combobox1.Items.Add('Drive ' + stlDrives[iCount]);
...

  //Now use the selection in the combobox to set the media player's drive
  MediaPlayer1.Filename := stlDrives[ComboBox1.ItemIndex];

Now that you have the mediaplayer setup, just get it to start playing by doing something like:

  MediaPlayer1.Play;

The Neil =:)
0
 

Author Comment

by:easysoft_studios
ID: 6203977
I've tried what, but nothing happens when I press the play button! And that DeviceType type should I use?
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 6205414
Ahh. Set the deviceType to be dtAutoSelect. You also need to open the mediaplayer (I forgot about that bit):

MediaPlayer1.Open;
MediaPlayer1.Play;

Then when you're finished (or need to switch the drive/file) you need to close the mediaplayer using:

MediaPlayer1.Close;

The Neil =:)
0
 

Author Comment

by:easysoft_studios
ID: 6206073
Won't work!

My Windows is Danish, so I don't know if this error message is correct translated:

"MMSystem This file could not be played. Check if the filename is correct, or install a driver who support this filetype"

It's a EMCIDeviceError
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:TheNeil
ID: 6207046
Do you have the audio CD player installed as part of Windows? I'm a bit baffled as TMediaPlayer should deal with all of this (along as Windows has the drivers installed).

I don't have an audio CD with me to test any code but from memory the following SHOULD work (as long as Windows is installed correctly)

procedure TForm1.Button1Click(Sender: TObject);
begin
  MediaPlayer1.DeviceType := dtCDAudio;
  MediaPlayer1.Filename := 'd:';
  MediaPlayer1.Open;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MediaPlayer1.Close;
end;

I simply started a new application, dropped a TButton (Button1) and a TMediaPlayer (MediaPlayer1) and then attached the above code to the button and the close event for the form. After the button is clicked, the mediaplayer should light up and hitting the Play button will play the CD

The Neil =:(
0
 

Author Comment

by:easysoft_studios
ID: 6209708
Nop! Then I try to eject the tray, for the drive I want to play from, the tray for the other (my defualt) drive opens!

It won't ofcourse play the disc, since there isn't any, in the drive (F:) and I wan't to play from G: !!
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 50 total points
ID: 6209779
Well it certainly explains the MCI error but I don't know why it won't select the drive. I've always just set the filename to be the drive letter and it's worked. Sorry but I'm out of ideas

The Neil =:(
0
 

Author Comment

by:easysoft_studios
ID: 6210794
Thanks anyway :-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now