Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pausing a Sound

Started by eyesonly_d Jan 2, 2002 at 10:07 AM 9 replies 450+ views
Original Post
eyesonly_d
eyesonly_d
What I want to do is stop the background music when I pause the game and then be able to start it up again when the game is resumed. Any help on how to go about this would be greatly appriciated. I am using VC++ 6 with DirectMusic 8. The format is MIDI if that makes any difference what-so-ever. Thanks Eyez
henryx
henryx
When the game is paused call the method:

IDirectMusicPerformance8::Stop

HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Kaijin
Kaijin
Is there a way to actually pause the sound so that it will continue from the point it was paused?

- Kaijin
eyesonly_d
eyesonly_d
Umm .. sorry I guess I was not so clear in the above post. Kaijin has the idea however. I''d want to pause the sound and have it start again where it left off. So far my attempts with stop() have been fruitless. Any help would be beyond appritiated.

Eyez
eyesonly_d
eyesonly_d
Umm .. sorry I guess I was not so clear in the above post. Kaijin has the idea however. I''d want to pause the sound and have it start again where it left off. So far my attempts with stop() have been fruitless. Any help would be beyond appritiated.

Eyez
henryx
henryx
I''ve been having a look at this too and as far as I can see there doesn''t seem to be any simple way to pause music in a midi file and start it up again when required from the point where it was paused. It is posible to stop the sound and start it again but that means it starts from the beginning again which is not what is required in many circumstances.

I''m using Direct Audio 8 and the IDirectMusicPerformance8 interface but there is no method to pause.

Any ideas would be appreciated.

henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
F104
F104
You can get the music time, stop the music and then set it again before calling Play().

Have fun!
KISS - Keep It Simple Stupid
Kaijin
Kaijin
quote:
Original post by F104
You can get the music time, stop the music and then set it again before calling Play().

Have fun!


Would IDirectMusicSegmentState8::GetSeek() do the trick or is that something different?

- Kaijin
henryx
henryx
Ok, here is a way to pause a midi file and continue it from the place it left off when unpaused. It might not be the best way but it works. Any comments appreciated.

There are three methods::

  

HRESULT CDirAudio::PlayAudio()
{

HRESULT Hr = E_FAIL;

//set the current music playing time

Hr = g_pSegment->SetStartPoint(StartTime);

// Play segment on the default audio path

Hr = g_pPerformance->PlaySegmentEx( g_pSegment, NULL, 0, 0,
0, &g_pSegmentState, NULL, NULL );

return Hr;

}

HRESULT CDirAudio::PauseAudio()
{
HRESULT Hr = E_FAIL;

//get the current music playing time

g_pSegmentState->GetSeek(&StartTime);

// Stop the music segment

if(g_pPerformance)Hr = g_pPerformance->Stop( NULL, g_pSegmentState, 0, 0 );

return Hr;

}

HRESULT CDirAudio::UnpauseAudio()
{
HRESULT Hr = E_FAIL;

if(!bAudioInitialised)
{
MessageBox( NULL, "Audio not initialised",
"DirectMusic Tutorial", MB_OK );
return Hr;
}


if( FAILED( g_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
wcharStr,
(LPVOID*) &g_pSegment ) ) )
{
MessageBox( NULL, "Media not found, sample will now quit",
"DirectMusic Tutorial", MB_OK );
return Hr;
}


// Download the segment''s instruments to the synthesizer

g_pSegment->Download( g_pPerformance );

//set infine looping

g_pSegment->SetRepeats(DMUS_SEG_REPEAT_INFINITE );

PlayAudio();


return Hr;

}


When the sound is paused the music time is stored in the class. This time is then used to start the music playing again when the music is unpaused. When the sound is unpaused the segment must be loaded and initialised again since the stop method unloads the segment.
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Kaijin
Kaijin
Stop doesn''t unload the music segment. It just stops the play of the specified segment or segment state.

- Kaijin
henryx
henryx
Kaijin, The documentation is not too good but I agree with you when you say that:

"Stop doesn''t unload the music segment. It just stops the play of the specified segment or segment state. "

However, after pausing the music with the code in my previous post if I simply call the play method there is no sound. This is why I have to load the segment again.

Henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.