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
2
Question by CtrlVDev04 · Apr 28, 2017 at 05:49 AM · unity 5vrlagurlvideos

How Can I Get Rid Of Lag When Using the VideoPlayer in 5.6?

I have a screen in one of my scenes that I want to use to cycle through various videos that are read from a local directory. An array of available videos is generated based on what is present at a specified path, and whenever one video finishes, the video player moves to the next one in the array. Once it is at the end of the array, it goes back to the first video.

The code works the way I'd like it to. The only problem is that whenever the url is changed, the game lags rather noticeably for a couple of seconds. What makes it even worse is that this is a VR application, so the headset will just go grey and show the Unity loading screen until it corrects itself.

I was wondering if anyone had any idea as to how I could optimize this code such that there wouldn't be any lag between videos.

 private void Update()
     {
         if (screen.url != "")
         {
             //Move to the next video once the current one is done
             if (screen.time > 0 && !screen.isPlaying)
                 if (currentVideo>= gamesWithTrailers.Length)
                     currentVideo = 0;
                 else
                     screen.url = gamesWithTrailers[currentVideo++].trailerPath;
          }
     }
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 andersemil · Aug 28, 2017 at 07:59 AM 0
Share

Did you find an answer to the lag? I have the same problem, I even tried upgrading to 2017.1 but the problem persists. @hurleybird ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by hurleybird · May 02, 2017 at 01:56 AM

I'm dealing with the same issue right now. As it stands, I don't believe there's any way around it. Hopefully this case gets addressed in a future version of the engine.

However, it's probably not a good idea to switch between clips in your update function since that could throw the timing off. Subscribe a method to VideoPlayer.loopPointReached instead. Eg.

     private VideoPlayer player;
     private string moviesFolder;
     private string[] fileNames;
     private int index;
 
     public void Awake()
     {
         moviesFolder = Application.dataPath.Remove(Application.dataPath.LastIndexOf('/')) + "/Game Data/Movies/";
         player.loopPointReached += PlayNext;
     }
 
     public void Play(string[] _fileNames)
     {
         index = 0;
         fileNames = _fileNames;
         player.url = moviesFolder + fileNames[index] + ".mp4";
         player.Play();
     }
 
     public void PlayNext(VideoPlayer vPlayer)
     {
         if (index < fileNames.Length - 1)
             index++;
         vPlayer.url = moviesFolder + fileNames[index] + ".mp4";
         vPlayer.Play();
     }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't query ID3D10Multithread interface 1 Answer

I want VRcamera to climb the stairs 0 Answers

How do I stream my desktop in the game? 1 Answer

How can I prevent Water4 on iOS lagging more/degrading over time? 1 Answer

Extremely low fps in editor!!! 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