Jump to content
  • Advertisement

Archived

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

eyesonly_d

Pausing a Sound

This topic is 6035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Is there a way to actually pause the sound so that it will continue from the point it was paused?

- Kaijin

Share this post


Link to post
Share on other sites
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
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
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
You can get the music time, stop the music and then set it again before calling Play().

Have fun!

Share this post


Link to post
Share on other sites
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
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
Stop doesn''t unload the music segment. It just stops the play of the specified segment or segment state.

- Kaijin

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!