Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Mattchuu · Sep 17, 2010 at 04:42 AM · pauseplaymusic

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by AliAzin · Sep 17, 2010 at 05:58 AM

You can save and restore your audio position with "AudioSource.time".

Hope this helps.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
3

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;
                 }

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FlintCLeaver · Sep 17, 2012 at 11:11 AM 0
Share

That's ingenious

avatar image phocker · Apr 30, 2014 at 12:06 AM 0
Share

thanks jackpile - that helped me out greatly

avatar image
0

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();

     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Music On/Off Switch 2 Answers

Is there any way to make the headphone pause/unpause controls work when the Unity app is running, to pause/unpause background app(apple music/google music) music? Android app. 0 Answers

Pause play button does not work. 0 Answers

Game freezes when i press play but when i press Esc it starts 0 Answers

Creating a play/pause button for animations. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges