Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 tex1820 · Jan 05, 2012 at 03:29 PM · movietexturemoviemovie texture is playing

On movie end

Hi Guys,

I am having an issue with triggering an event when a movie completes. I am using the isPlaying property of the movie texture to check however it is never set to true.

     GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), Intro);

 Intro.Play();

 if(Intro.isPlaying == false) {

     GUI.Label(Rect(25, Screen.height / 2, 500, 500), "Here is some Content", IntroText);
     Debug.Log("Video NOT Playing");

 } else {

     Debug.Log("Video Playing");

 }

Any Ideas on how I can trigger an event when the movie ends?

Thanks.

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 tex1820 · Jan 06, 2012 at 03:56 AM 0
Share

Sorry to bump this but dose anyone have an answer? I am on a deadline

2 Replies

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

Answer by Fattie · Jul 05, 2015 at 08:52 AM

Simply loop on isPlaying...

 public void PlayThenDoSomething(Action callback)
     {
     mt.Stop();
     mt.Play();
     StartCoroutine(FindEnd(callback));
     }
 
 private IEnumerator FindEnd(Action callback)
     {
     while(mt.isPlaying)
         {
         yield return 0;
         }
     
     callback();
     yield break;
     }
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 alexfeature · Feb 08, 2012 at 07:10 PM

Hi Tex,

Here is something that may help you.

 void PlayMyClip()
 {    

  if(!Intro.isPlaying)
  {
     // Play clip
     Intro.Play();

     // Wait for the clip to finish
     StartCoroutine(Wait(_currentClip.duration));

     //
     // Add your code here
     //
 
  }
 
 }

 private IEnumerator Wait(float duration)
 {
     yield return new WaitForSeconds(duration);
 }


The idea is pretty simple. First you trigger the clip to play and then wait for it to finish using yield. Once it finishes playing you can carry on with your other stuff.

You can of course send a message after the wait function call or do something a little more advanced (read complicated :) ) depending on your actual requirements.

Hope this helps.

Comment
Add comment · Show 3 · 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 cowlinator · Nov 13, 2014 at 01:57 AM 0
Share

So what happens if the video pauses for a while?

avatar image alexfeature · Nov 13, 2014 at 06:51 AM 0
Share

You skip ahead and everything goes out of sync. Simple :)

avatar image Sylafrs · Sep 25, 2015 at 09:19 AM 0
Share

Your code doesn't work. You need to wait your coroutine, so Play$$anonymous$$yClip must be a coroutine itself.

  IEnumerator Play$$anonymous$$yClip()
  {    
   if(!Intro.isPlaying)
   {
      // Play clip
      Intro.Play();
      // Wait for the clip to finish
      yield return StartCoroutine(Wait(_currentClip.duration)); // at this point, you can use new WaitForSeconds here, directly
      //
      // Add your code here
      //
  
   }
  
  }
  private IEnumerator Wait(float duration)
  {
      yield return new WaitForSeconds(duration);
  }

There is a second option (I don't like it) : using callbacks

  void Play$$anonymous$$yClip()
  {    
   if(!Intro.isPlaying)
   {
      // Play clip
      Intro.Play();
      // Wait for the clip to finish
      StartCoroutine(Wait(_currentClip.duration, OnWaitFinished)); 
   }     
  }

  private void OnWaitFinished()
 {
      //
      // Add your code here
      //
 }
  private IEnumerator Wait(float duration, System.Action callback)
  {
      yield return new WaitForSeconds(duration);
      if(callback != null) callback();
  }

Note that this kind of StartCoroutine * Wait function already exists on Unity : Invoke. http://docs.unity3d.com/es/current/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html

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

6 People are following this question.

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

Related Questions

Movie Texture 0 Answers

www.movie.other formats 1 Answer

MovieTexture stops playing after first frame 0 Answers

Movie Texture and EndUser's PC 0 Answers

problem about hiccups during play video? 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