• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

JavaScript Play Audiosource Problem 1 Answer

AudioSource.PlayOneShot playing loud and garbled 1 Answer

Play audio at consistent volume 2 Answers

Looping an audio while holding "shift key" 1 Answer

Can an object check on other objects? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges