Archived

This topic is now archived and is closed to further replies.

eyesonly_d

Pausing a Sound

Recommended Posts

eyesonly_d    122
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

Share this post


Link to post
Share on other sites
eyesonly_d    122
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

Share this post


Link to post
Share on other sites
eyesonly_d    122
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

Share this post


Link to post
Share on other sites
henryx    128
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

Share this post


Link to post
Share on other sites
Kaijin    163
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

Share this post


Link to post
Share on other sites
henryx    128
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.

Share this post


Link to post
Share on other sites
henryx    128
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

Share this post


Link to post
Share on other sites