Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by Afthrast · Jun 03, 2018 at 08:02 PM · timeaudiosourceaudioclippausetimeline

How to stop Audio Track in Timeline?

I've tried finding the AudioSource which the Timeline creates to play it's sound (even when there's a reference in the TimelineAsset) when started through the PlayableDirector's Play function, without any success. I've tried FindObjectsOfType/Resources.FindObjectsOfTpyeAll, neither will find it. Setting the Time.timeScale won't stop a started AudioTrack from playing through the Timeline. Setting the Timeline's PlayableGraph's speed (suggested by a Unity forum employee in another post to "Pause" the timeline) won't stop it either. Pausing the Timeline won't either. Basically I've ran out of ways I could find to "Pause" the Timeline in different ways, and all of them would continue to play the AudioClip that has already started from the AudioTrack. I would welcome a way where I can find a reference to the AudioSource that the Timeline made, but so far I didn't have any luck with it.

Comment
Add comment · Show 3
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 roman_sedition · Nov 07, 2018 at 05:11 PM 0
Share

Did you ever find an answer to this? @Afthrast

avatar image Afthrast roman_sedition · Nov 07, 2018 at 10:36 PM 0
Share

No, I haven't. I ended up just simply not allowing pausing while audio was playing through the timeline and keep trying to avoid using it for that end. Alas, I'm stuck with a rather old Unity version with my project due to some asset compatibility issues, so I wouldn't know if the Timeline has been improved on since.

avatar image roman_sedition Afthrast · Nov 08, 2018 at 04:11 AM 0
Share

Yeah I don't think it's been fixed yet in the later versions either. For some reason it looks like like the Audiosource you assign to it in the timeline bypasses the Audiolistener so Audiolistener.Pause doesn't work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by roman_sedition · Nov 08, 2018 at 08:20 AM

@Afthrast Ok well I've found one solution around this. It requires that the timeline tracks have an audiosource assigned to it for this to work. After you pause the sounds you normally can with Audiolistner.pause = true you find out what audio is currently being played on the timeline and then you turn the volume to zero (that is the first part of the band-aid fix to stop the current sounds from playing), then after that you use the current time of the timeline playing to figure out the offsets of the clips that were playing, you then reassign those clips to the Audiosources that were silenced and play them again and change their Audiosource.time to what the offset was. In your unpause method you then go through a list of Audiosources you have silenced and revert their volumes back to 1.

Here is some code that I came up with

     private List<AudioSource> audioPlayers;//This is mainly for use in your unpause method
 
  //Call this method in your pause method
  private void PauseTimelineAudio(PlayableDirector _director)
     {
         audioPlayers.Clear();
         var timelineAsset = _director.playableAsset as TimelineAsset;
 
         double pauseTime = _director.time;
 
         foreach (var track in timelineAsset.GetOutputTracks())
         {
             AudioTrack pausedAudioTrack = track as AudioTrack;
 
             if (pausedAudioTrack == null)
             {
                 continue;
             }
             IEnumerable<TimelineClip> trackList = pausedAudioTrack.GetClips();
             foreach (TimelineClip timeClip in trackList)
             {
                 if (pauseTime >= timeClip.start && pauseTime <= timeClip.end)
                 {
                     
 
                     foreach (var playableAssetOutput in _director.playableAsset.outputs)
                     {
                         foreach (var clipOutput in timeClip.parentTrack.outputs)
                         {
                             if(playableAssetOutput.sourceObject == clipOutput.sourceObject)
                             {
 
                                 AudioSource audio = _director.GetGenericBinding(clipOutput.sourceObject) as AudioSource;
                                 audioPlayers.Add(audio);
                                 if(audio == null)
                                 {
                                     continue;
                                 }
                                 audio.volume = 0;
                                 AudioPlayableAsset ac = timeClip.asset as AudioPlayableAsset;
                                 pausedClip = ac.clip;
                                 resumeTime = (pauseTime - timeClip.start);
                                 audio.clip = pausedClip;
                                 audio.time = (float)resumeTime;
                                 audio.Play();
 
                             }
                             
                         }
                     }
                 }
 
             }
         }
     }
 
 
 
 //In your unpause method, paste this to re-volumize the audiosources that were silenced
 foreach(AudioSource sound in audioPlayers)
             {
                 if(sound != null)
                 {
                     sound.volume = 1;
                 }
 
             }
Comment
Add comment · Show 1 · 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 Afthrast · Nov 08, 2018 at 08:02 PM 0
Share

I wasn't able to test it yet and sadly won't be around for a while to do so, so if anyone can confirm this works, I'd be happy to mark it as an answer for those, who find this helpful. As for me, if it requires the timeline track to have an audiosource assigned to it, it won't be an option for me sadly, as I need to assign the playable asset to the director at runtime (depending on a choice that the player makes), I use the director's Play() to start a timeline. With simply selecting the timeline asset, there is no such option as to assign an audiosource to it, only after assigning it in the director's reference. I was mainly interested if I was missing something, because it would've made sense to me, that the director itself would have to contain the audiosource it creates, when it's not assigned (since it manages to stop it when the timeline finishes part of the audio it's supposed to play), and being able to reach it would've made sense to me, but I wasn't able to find a way to get the reference to it.

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

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Timeline AudioClip ease not working 1 Answer

Timecale=0 stops joystick. can it not? 1 Answer

Can I make an audio source play its clip starting at a time in the clip besides the beginning? 1 Answer

Audio Manager 1 Answer

MissingComponentException: no AudioClip even if i add it 1 Answer


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