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
0
Question by vrbullshit · May 18, 2017 at 11:01 AM · videovideotexturemovie

Unity 5.6 videoplayer: How to get the total length of a video?

How do I get the total length of a video played back in the videoplayer (new since Unity 5.6)? A C# code snippet would be awesome! I need this for a couple of things, e. g. for creating a progress bar. Thanks

Comment
Add comment · Show 2
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 kharal · May 17, 2017 at 10:03 AM 0
Share

You can start with following script.

 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine; 
 using UnityEngine.Video; 
 using UnityEngine.UI; 
 using System;
 public class VIdeoBeheviour : $$anonymous$$onoBehaviour {
  public VideoPlayer vplayer;
  public Slider videoslider;
  public bool dragging = false;
  void Start()
  {     
      vplayer.Play ();
      Debug.Log ("started " + vplayer.frameCount);
  }
  void Update() 
  {   
      if (dragging) {   
          vplayer.frame = Convert.ToInt64 (videoslider.value);     
          }
  else 
      {
          videoslider.maxValue = vplayer.frameCount;
          videoslider.value = vplayer.frame;
      }
      //Debug.Log ("update " + vplayer.frame + " " + vplayer.frameCount + " " + videoslider.value);
  }
  public void OnBeginDrag()
  {
      
      dragging = true;
  }
  public void OnEndDrag()
  {   
      dragging = false;
  }
  }

BESIDE This you need to create add event trigger for the slider as shown in the picture .....i just created this script few days ago ....It works fine for unity engine , perhaps desktop also but it is slow for android i will keep you up to date if i find the solution . For creating event trigger :- go to add component and add event trigger Add a new event type onpointerdown and onpointerup * put the above script on a gameobject and and drag that gameobject in the second picture area .... now see the first image and implement the same functions.

There are some debug functions its for my own purpose but you can skip it on script if you want.

:)

alt text

two.png (8.3 kB)
one.png (81.9 kB)
avatar image vrbullshit · May 18, 2017 at 07:20 AM 0
Share

@kharal Your example is awesome! $$anonymous$$any thanks! Attached the UnityPackage demonstrating this for download. link text

videoslidertesterunitypackage.zip (492.7 kB)

2 Replies

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

Answer by ashishsfb · May 17, 2017 at 07:22 AM

@vrbullshit Length of a video is the property of a video clip instead of the video player. So to get the length of a video clip, through a video player you can use

 float length = videoPlayer.clip.length;


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 vrbullshit · May 18, 2017 at 07:23 AM 0
Share

@ashishsfb Thanks! It works. However, it´s a double, not a float.

avatar image
0

Answer by divdanila · Jan 29, 2018 at 01:42 PM

А если я использую videoPlayer.url ?

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

Play, seek a video 1 Answer

How to play video on WEBGL 0 Answers

Unity4.7.2 IOS13.1 Handheld.PlayFullScreenMovie can't play video. 0 Answers

VideoPlayer Completed Event Handler 0 Answers

Project a video Texture using Unity5's Projector 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