Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Vuzok · Jul 20, 2016 at 01:16 AM · audioaudiosourceaudioclipaudio sourceaudio.play

AudioSource.clip.time won't work?

Unity seems to be telling me that AudioSource.clip.time doesn't exist? Does it? I know AudioSource.time does and I have AudioSource.clip.length working so why can't I get AudioSource.clip.time to work?

I am trying to make an audiosource shuffle between songs. At the moment it can tell when the first song has ended by using the AudioSource.time but the problem is that after that it can't tell when the next song has ended unless there was a way to get the AudioSource.clip.time. Any help would be super helpful because this is driving me insane!

 using UnityEngine;
 using System.Collections;
 
 public class Juke : MonoBehaviour
 {
     public float time;
     public AudioClip[] whopperBeats;
     public AudioSource radioStation;
 
     public int randomclipNumber;
     public int lastTrack;
 
     // Use this for initialization
     void Start()
     {
         Tunes();
         lastTrack = 481516;
     }
 
     void Tunes()
     {
         randomclipNumber = Random.Range(0, whopperBeats.Length);
 
         radioStation.clip = whopperBeats[randomclipNumber];
        radioStation.Play();
         
         
         
     }
 
     void Update ()
     {
         lastTrack = 0 + randomclipNumber;
 
         if (randomclipNumber == lastTrack)
         {
             //Tunes();
             print("Re-Shuffle Initiated");
         }
 
         if (radioStation.clip.time >= radioStation.clip.length -1)
         {
             print("Play a new tasty beat.");
             //Tunes();
         }
     }
 
 }
Comment
Add comment · Show 1
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 ScaniX · Jul 20, 2016 at 08:12 AM 0
Share

As the clip can be used in multiple AudioSources at the same time, it cannot have a value for the current position.

AudioSource.time returns the time of the current clip. I don't think you need to reset anything.

AudioSource.time and AudioClip.length work perfectly to show the current music track progress for me.

2 Replies

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

Answer by Vuzok · Jul 20, 2016 at 01:43 AM

Ok so for anyone running into a similar issue in the future I didn't find a way to use AudioSource.clip.time and I don't think that it exists. I ended up just resetting AudioSource.time back to zero each time a clip finished playing.

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
0

Answer by Arkaid · Jul 20, 2016 at 01:34 AM

Because it's AudioSource.time, not AudioSource.clip.time

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 Vuzok · Jul 20, 2016 at 01:46 AM 0
Share

Yeah I know that but thats not what I am looking for. I don't think you read the question fully. AudioSource.time gives you the time that the AudioSource has been playing for. What my question asked was how to get the time that the current audio clip has been playing for- and no I can't use AudioClip.length because when you try use that on an audio array it returns with the value of the array ins$$anonymous$$d of the length of the clip. Like I said in the question I did already use AudioSource.time but thats not what I am looking for. Thanks for the response anyway I found a workaround.

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

58 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

Related Questions

Looping an audio while holding "shift key" 1 Answer

Can an object check on other objects? 1 Answer

Audiosource.Play() not working 0 Answers

Breathing volume increases as player gets more tired 0 Answers

Assign a clip to an AudioSource when it finishes playing. 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