Reputation: 41128
I have this class I found in a website:
class MP3Handler
{
private string _command;
private bool isOpen;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
public void Close()
{
_command = "close MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isOpen = false;
}
public void Open(string sFileName)
{
_command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isOpen = true;
}
public void Play(bool loop)
{
if (isOpen)
{
_command = "play MediaFile";
if (loop)
_command += " REPEAT";
mciSendString(_command, null, 0, IntPtr.Zero);
}
}
}
Is has the methods for STOP and PLAY. I was wondering if anyone is familiar with the winmm.dll library. How can I pause the song as it's playing and then continue from where it was paused?
Upvotes: 2
Views: 3130
Reputation: 2807
This CodeProject article contains a class which handles may of the functions of the winmm.dll library, including pause, and may be helpful for this and in the future.
The basic code, however, is:
_command = "pause MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
Upvotes: 2
Reputation: 70983
Here are all the Multimedia Command Strings.
I see the pause and resume commands are included:
The pause command pauses playing or recording. Most drivers retain the current position and eventually resume playback or recording at this position. CD audio, digital-video, MIDI sequencer, VCR, videodisc, and waveform-audio devices recognize this command.
The resume command continues playing or recording on a device that has been paused using the pause command. Digital-video, VCR, and waveform-audio devices recognize this command. Although CD audio, MIDI sequencer, and videodisc devices also recognize this command, the MCICDA, MCISEQ, and MCIPIONR device drivers do not support it.
So I guess you would have:
bool isPaused = false;
public void Pause() {
if (isOpen && !isPaused) {
_command = "pause MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isPaused = true;
}
}
public void Resume() {
if (isOpen && isPaused) {
_command = "resume MediaFile";
mciSendString(_command, null, 0, IntPtr.Zero);
isPaused = false;
}
}
Upvotes: 0