- Home /
Continueing music after un-pausing
I want music to continue after un-pausing from where it stopped when you first paused. my script so far:
var nextSong1 : int = 0; var myPlaylist1 : AudioClip;
function Update() { if ( Input.GetKeyDown("p") ){ // 'p' has been pressed PlayNextSong1(); // play the next song }
} function PlayNextSong1 () { if ( audio.isPlaying ) { // if there is audio playing audio.Pause(); // stop it audio.clip = myPlaylist1; // set the audio clip to the next in the array audio.Play(); // start the 'nextSong' playing }
if (audio.Pause ) { // if there is audio playing audio.Play(); }
}
what can i do?
Answer by AliAzin · Sep 17, 2010 at 05:58 AM
You can save and restore your audio position with "AudioSource.time
".
Hope this helps.
Answer by jackpile · Nov 26, 2011 at 10:34 PM
I know this is an old thread, but I came across this issue too and am using mp3's to save space. I happen to instantiate an audio prefab and have multiple music/background sources, so I found it convenient to simply stuff the time value into the AudioSource (a in this case) localScale transform for safe keeping since the scale of a lone AudioSource GameObject is meaningless and I didn't want to create some additional storage for this silly thing. Something like:
if (mute) {
a.Pause ();
a.transform.localScale = new Vector3(a.time,0,0);
} else {
a.Play ();
a.time = a.transform.localScale.x;
}
Answer by Bwhang · Sep 19, 2016 at 09:18 PM
I'm using Unity 5.3.4f1 and the following (UnPause) makes the music resume at the point where it was paused. I use mp3s for my songs and the following is in Javascript.
if (paused == true) {
GetComponent.<AudioSource>().Pause();
}
else if (paused == false) {
GetComponent.<AudioSource>().UnPause();
}
Your answer
Follow this Question
Related Questions
Music On/Off Switch 2 Answers
Audio keeps playing when paused 1 Answer
Pause game music during different other UI activity 0 Answers
Streaming music from a folder or file 0 Answers