Is there a way to pause the audio while a "Save/Load/Quit" gui is up? If I stop the audio and the player decides to return to "play" or "save" then it is kinda tricky knowing which audio to start up again (don't have all the music on channels) since that gui can come up anywhere in the game.
There's no built-in method, but you can script one:
// Script.ash
import void PauseAudio(AudioType);
import void UnPauseAudio();
// Script.asc
AudioClip *pausedAudio;
int pausedAudioPosition;
void PauseAudio(AudioType type)
{
int i = 0;
while (i < System.AudioChannelCount)
{
if ((System.AudioChannels[i].IsPlaying) && (System.AudioChannels[i].PlayingClip != null) && (System.AudioChannels[i].PlayingClip.Type == type))
{
pausedAudio = System.AudioChannels[i].PlayingClip;
pausedAudioPosition = System.AudioChannels[i].Position;
System.AudioChannels[i].Stop();
return;
}
i++;
}
}
void UnPauseAudio()
{
if (pausedAudio == null) return;
pausedAudio.PlayFrom(pausedAudioPosition);
pausedAudio = null;
pausedAudioPosition = 0;
}
It's somewhat basic in that it will only pause one instance of the specified type, but it should work for your music (which is what you wanted it for, right?).
Usage is like this:
// show GUI:
gMenu.Visible = true;
PauseAudio(eAudioTypeMusic);
// hide GUI:
gMenu.Visible = false;
UnPauseAudio();
Hmmm, maybe it's an idea to turn down the volume? Then you would still have a gap but that might be not that noticeable. :)
Cool, I've give this a shot. If it doesn't work, I'll use the volume. Ahem, didn't even think of that.
On this line:
if ((System.AudioChannels.IsPlaying) && (System.AudioChannels.PlayingClip != null) && (System.AudioChannels.PlayingClip.Type == type))
I am getting an error msg.
must have an instance of the struct to access a non-static member
Oh right, sorry. Replace that line with:
AudioChannel *channel = System.AudioChannels[i];
if ((channel.IsPlaying) && (channel.PlayingClip != null) && (channel.PlayingClip.Type == type))
Then replace the lines:
pausedAudio = System.AudioChannels[i].PlayingClip;
pausedAudioPosition = System.AudioChannels[i].Position;
System.AudioChannels[i].Stop();
With:
pausedAudio = channel.PlayingClip;
pausedAudioPosition = channel.Position;
channel.Stop();
Works like a charm!!!
Yes, sometimes I forget about that compiler limitation, but it's simple enough to get around it. In any case, glad to hear you got it working! :)
I need some help with this code. I've used the above code and most of the time it works. There are occasions when I come back from the Save and the music is no longer playing. What am I missing?