• 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 dibonaj · Jul 28, 2011 at 02:20 PM · audiomovie

Getting length of a movie

Hello all. I have a coroutine that waits for the length of a soundclip to finish before moving on to the next part. However, I'm having issues using this with a movie sound. I have a variable set up where I put in an audioclip, and for the audio clips I bring in myself it works. But if I put in the audio file that Unity makes when importing a video it doesn't work. Is it possible for me to access the length of the audio clip from a movie, or just get the duration of the movie itself?

Comment
Add comment · Show 13
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 dibonaj · Jul 28, 2011 at 02:33 PM 0
Share

Interesting note: when I write a debug.log line that prints the length of the audio clip I got from the movie, it returns a value of -1.

avatar image Graham-Dunnett ♦♦ · Jul 28, 2011 at 02:40 PM 0
Share

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$ovieTexture-duration.html?

avatar image dibonaj · Jul 28, 2011 at 03:11 PM 0
Share

I have tried that. It doesn't seem to work.

avatar image Dreamora · Jul 29, 2011 at 10:19 AM 0
Share

If you use WWW to load it, you need to play it a frame to get its length. Before its played for at least 1 frame, its data are not yet known.

avatar image dibonaj · Aug 02, 2011 at 04:06 PM 0
Share

I'm not using WWW to load it though. It is a video we made and edited, and then imported it as an asset.

Show more comments

1 Reply

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

Answer by Dreamora · Aug 02, 2011 at 08:09 PM

One way to solve the problem is to just check if the movie has finished already. You would do this through (in C#, UnityScript is the same just yield instead of yield return null)

 while(movie.isPlaying)
 {
  DoSomethingEachFrame;
  yield return null;
 }
 DoWhatYouWantWhenMovieHasFinished;

Thats what I am using myself as well

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

WWW.movie doesn't work 1 Answer

Unity Movie Texture First Few Seconds Black 1 Answer

movie audio not functioning 0 Answers

How to get perfect sync between audio and video? 0 Answers

Unity Movie Texture Audio Black Screen 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