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 /
  • Help Room /
avatar image
0
Question by RyanAchtenSoma · Feb 22, 2016 at 08:37 AM · coroutinewwwruntimemovietexture

Issues with video player coroutine

Hi Unity Community

I have a coroutine downloading an .ogg file at runtime via the www class, this is currently really inconsistent...

The video is intended to display at its normal size (320 x 240px), and sometimes this works. alt text

However, a lot of the time the video is displayed at 16 x 16px. alt text

It seems to me that this is largely due to the video not being downloaded completely using the current coroutine. I have followed the docs to the best of my ability but to no avail, if anyone has any suggestions as to why this may be occurring I would be very grateful.

NB: scripting in uJS.

Many thanks in advance, Ryan

 function loadContextVideo(texLocation : String)
 {
     var wwwDirectory = "file://" + texLocation; 
     
     var vidTex = www.movie;    //method 01 [using local variables]
 //    vidTex = www.movie;    //method 02 [using public variables]
         
     while(!vidTex.isReadyToPlay){ //****PROBLEM COROUTINE*****
         yield www;
         if (www.isDone)
         {
             break;
         }
     }
 
     var texWidth = vidTex.width;
     var texHeight = vidTex.height;
     Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);
     
     //check img sizes
     var mvMaxWidth = imgRect.rect.width;
     var mvMaxHeight = imgRect.rect.height;
     Debug.Log("mvMaxWidth: " + mvMaxWidth + " mvMaxHeight: " + mvMaxHeight);
     
     if (texHeight > mvMaxHeight)
     {
         var scaleHFactor = mvMaxHeight /texHeight;
         texHeight = texHeight * scaleHFactor;
         texWidth = texWidth * scaleHFactor;        
     }
     if (texWidth > mvMaxWidth)
     {
         var scaleWFactor = mvMaxWidth /texWidth;
         texHeight = texHeight * scaleWFactor;
         texWidth = texWidth * scaleWFactor;
     }
     Debug.Log("texWidth: " + texWidth + " texHeight: " + texHeight);
     imgRect.sizeDelta = new Vector2(texWidth, texHeight);
     
     //Video Tex assign
     var imgView : UI.RawImage = imageView.GetComponent.<RawImage>(); //method 01 [using local variables]
 //    var imgView = imageRender; //method 02 [using public variables]
     imgView.texture = vidTex;
     
     //Video Audio assign
     var vidAudio : AudioSource = imageView.GetComponent.<AudioSource>(); 
     vidAudio.clip = vidTex.audioClip;
 
     //curVideo = vidTex;
     vidTex.Play();
     vidAudio.Play();    
 }


screen-shot-2016-02-20-at-75446-pm.png (204.5 kB)
screen-shot-2016-02-20-at-73230-pm.png (350.0 kB)
Comment
Add comment
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

2 Replies

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

Answer by RyanAchtenSoma · Feb 25, 2016 at 08:30 AM

The issue seems to be a frame gap between the downloading being ready and the video file being ready. The answer to resolving this is to check both whether the www.file is done downloading and whether the video file is ready to be played as in the code below:

 function loadContextVideo(texLocation : String)
 {
     var wwwDirectory = "file://" + texLocation;
     var www : WWW = new WWW(wwwDirectory);
     
     vidTex = www.movie;
         
 //    while(!vidTex.isReadyToPlay){ //problem coroutine
 //        yield www;
 //        if (www.isDone)
 //        {
 //            break;
 //        }
         while(!www.isDone && !vidTex.isReadyToPlay){ //answer coroutine
         yield www;
         if (www.isDone && vidTex.isReadyToPlay)
         {
             break;
         }
     }
 
     var texWidth = vidTex.width;
     var texHeight = vidTex.height;
 
 //rest of the code continues...
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 Pratap-Dafedar · Feb 25, 2016 at 08:30 AM

This is usual thing, which even happens in youtube as well. If internet is slow, then youtube will automatically plays lower resolution format of video. and changes to high when speed is good. because of auto adjustment.

Even the doc says the samething.

Even if the movie is not yet completely downloaded, this returns immediately, allowing you to start playing the partial movie as it downloads.

So you shouldn't rely on the size(Rect) of the movie downloaded. Make a fixed width height for video player. and play the downloaded video. And then it should play 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.

Follow this Question

Answers Answers and Comments

38 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

Related Questions

Need Coroutine Download to finish first 1 Answer

Streaming video as MovieTexture 2 Answers

How to do very accurate time measurement 3 Answers

Loading Shader at Runtime from Asset Bundle 1 Answer

MovieTexture.duration returning consistently incorrect duration 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