// File: simplecd.cxx // Written by: Michael Main // Note: This function must link with library winmm.lib: // Project-->Properties-->ConfigurationProperties-->Linker-->Input // and then click to the right of Additional Dependencies // click the ... button that appears // type the name winmm.lib in the text box // and click Apply // // This simple program demonstrates some of the commands that can be sent to // the MCI (Media Control Interface) to control the cd player. // This works if you have only one cd player. For multiple players, // you would need to use the sysinfo function to get the names of // the different cd audio devices, according to page 1281 of Petzold.) // // Current commands that this program accepts from the keyboard: // C: Close the cdaudio device // O: Open the cdaudio device and set its time format to tmsf // (track:minute:second:frame) // E: Eject the cd (won't work for all hardware) // P: Play from the start // S: Stop playing // T: Play a track (the user types the track number) // Q: Quit #include // Provides cin #include // Provides the ostringstream #include // Provides bgi graphics and mciSendString using namespace std; int main( ) { char c; char buffer[100]; int track; ostringstream command; MCIERROR error; do { cin >> c; c = toupper(c); switch (c) { case 'C': error = mciSendString("close cdaudio notify", NULL, 0, NULL); break; case 'E': error = mciSendString("eject cdaudio", NULL, 0, NULL); break; case 'O': error = mciSendString("open cdaudio", NULL, 0, NULL); if (error != 0) { cout << "Could not open cdaudio" << endl; exit(0); } error = mciSendString("set cdaudio time format tmsf", NULL, 0, NULL); break; case 'P': error = mciSendString("play cdaudio", NULL, 0, NULL); break; case 'S': error = mciSendString("stop cdaudio", NULL, 0, NULL); break; case 'T': cin >> track; command.str(""); // Set the command to the null string command << "play cdaudio from " << track << " to " << track+1; error = mciSendString(command.str().c_str( ), NULL, 0, NULL); break; case '?': error = mciSendString( "status cdaudio number of tracks", buffer, 100, NULL ); cout << "The CD has " << buffer << " tracks." << endl; break; } if (error != 0) cout << "Error. This program does not yet handle errors." << endl; } while (c != 'Q'); return 0; }