A program that plays a MIDI file and stops it, and than starts a different MIDI file. The same concept applies to .wav files mciSendString("play the_file",NULL,0,NULL); starts playing it, and as expected mciSendString("stop the_file",NULL,0,NULL); stops playing it.
Stopping and playing a midi file
// use mciSendString() to play and stop a midi music file
// you have to link with the winmm.lib file, or
// in the case of Dev-C++ link with libwinmm.a via
// Project>>Project Options>>Parameters>>Add Lib>>libwinmm.a
// a Dev-C++ console application
#include <iostream>
#include <windows.h>
#include <mmsystem.h> // mciSendString()
#include <conio.h>
using namespace std; // std::cout, std::cin
int main()
{
char wait;
cout << "Looking for onestop.mid midi music file in" << endl;
cout << "the windows media directory, wait just a second ...";
// this midi file comes with Windows XP
// you might have to change it to something you have
mciSendString("play C:\\Windows\\Media\\onestop.mid",NULL,0,NULL);
cout << endl << "Enter any letter to change to the next file.";
getch(); // wait
cout << endl << "Stopping onestop.mid" << endl;
mciSendString("stop C:\\Windows\\Media\\onestop.mid",NULL,0,NULL);
// stops the file ^
cout << "Looking for flourish.mid midi music file in" << endl;
cout << "the windows media directory, wait just a second ...";
// this midi file comes with Windows XP also
mciSendString("play C:\\Windows\\Media\\flourish.mid",NULL,0,NULL);
getch(); // wait
return 0;
}
bumsfeld 413 Nearly a Posting Virtuoso
eagleeye 0 Junior Poster in Training
VASH007 0 Newbie Poster
Yuichi 0 Newbie Poster
tamtamtaramtam 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.