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
0
Question by KnightRiderGuy · Mar 17, 2015 at 08:25 PM · uimovietextureurluifontmovie texture is playing

How To Fetch movie Name From URL

Is there a way to display a movie name or title that is at the end of a url as a UI text on a canvas or panel so you can display a movie title? My script for how I am playing my movie is posted down below: Is it even possible to do this???

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Events;
 using System.Collections;
 
 public class DynamicVideoX : MonoBehaviour {
     
     public string _url = "http://www.unity3d.com/webplayers/Movie/sample.ogg";
     
     public RawImage texture;
     private MovieTexture movieTexture;
     private WWW www;
     
     public bool autoPlay = true;
     private bool autoPlayed = false;
     
     public bool loop = true;
     
     //events
     UnityEvent VideoStart = new UnityEvent ();
     UnityEvent VideoEnd = new UnityEvent ();
     
     //fades
     private float alpha = 1f;
     public bool fadeIn = true;
     public bool fadeOut = true;
     public float fadeInDuration = 2.0f;
     public float fadeOutDuration = 2.0f;
     private bool isFadingIn;
     private bool isFadingOut;
     private float alphaStart;
     private float fadeCounter = 0.0f;
 
     // Reference to my UI Display Text for Movie Now Playing
     public Text NowPlayingText;
     private string display = "";
     
     //timer
     public Text TimeCodeCurrent;
     public Text TimeCodeDuration;
     private float currentTime = 0;
     
     //video complete verification
     private bool isPlaying = false;
     private int frameFreezedMax = 3;
     private int frameFreezedCounter = 0;
     private float lastCurrentTime = 0;
     
     void Start () {
         Url = _url;
     }
     
     void Update () {
         
         //autoPlay
         if (autoPlay && !autoPlayed && !movieTexture.isPlaying && movieTexture.isReadyToPlay) {
             autoPlayed = true;
             Play ();
         }
         
         //update alpha
         if((isFadingIn || isFadingOut) && movieTexture.isReadyToPlay){
             fadeCounter += Time.deltaTime;
             
             if (isFadingIn) {
                 if (alpha < 1f) {
                     alpha = Mathf.Lerp(alphaStart, 1, fadeCounter/fadeInDuration);
                 } else {
                     //fadeIn complete
                     alpha = 1.0f;
                     isFadingIn = false;
                 }
             }
             
             if (isFadingOut) {
                 if(alpha>0f) {
                     alpha = Mathf.Lerp(alphaStart, 0, fadeCounter/fadeOutDuration);
                 }else{
                     //fadeOut complete
                     alpha = 0.0f;
                     isFadingOut = false;
                 }
             }
         }
         texture.color = new Color (texture.color.r, texture.color.g, texture.color.b, alpha);
         
         //update texture and timer
         if (movieTexture.isPlaying) {
             texture.texture = movieTexture;
             currentTime += Time.deltaTime;
         }
         
         //verify video complete
         if (isPlaying) {
             //it checks if the movie has stop update, and after some frames it considers it is completed
             frameFreezedCounter = currentTime == lastCurrentTime ? frameFreezedCounter+1 : 0;
             if(frameFreezedCounter == frameFreezedMax) OnVideoEnd();
             lastCurrentTime = currentTime;
         }
         
         //update timecode
         if(TimeCodeCurrent) TimeCodeCurrent.text = string.Format("{0:mm:ss; mm:ss}", System.TimeSpan.FromMinutes(currentTime));
         if(TimeCodeDuration) TimeCodeDuration.text = string.Format("{0:mm:ss; mm:ss}", System.TimeSpan.FromMinutes(movieTexture.duration));
     }
     
     private void OnVideoStart(){
         VideoStart.Invoke ();
     }
     
     private void OnVideoEnd(){
         VideoEnd.Invoke ();
         if (loop) {
             Stop (false);
             Play (false);
         } else {
             Stop ();
         }
     }
     
     public string Url
     {
         get { return _url; }
         set {
             _url = value;
             www = new WWW(_url);
             
             movieTexture = www.movie;
             if(GetComponent<AudioSource>()) GetComponent<AudioSource>().clip = movieTexture.audioClip;
             
             autoPlayed = false;
             
             if(fadeIn) alpha = 0.0f;
         }
     }
     
     public float CurrentTime
     {
         get { return currentTime; }
     }
     
     public float Duration
     {
         get { return movieTexture.duration; }
     }
 
     //NEW
     void AddText()
     {
         //Need Code Here To Display Current Movie Tittle Playing???
         NowPlayingText.text = display;
     }
     //END NEW
     
     public void Play(bool canFadeIn = true) {
         isPlaying = true;
         movieTexture.Play ();
         if(GetComponent<AudioSource>()) GetComponent<AudioSource>().Play ();
         if(currentTime==0) OnVideoStart();
         if(canFadeIn && fadeIn && alpha<1.0f) {
             fadeCounter = 0;
             alphaStart = alpha;
             isFadingIn = true;
             isFadingOut = false;
         }
     }
 
     public void Stop(bool canFadeOut = true) {
         isPlaying = false;
         movieTexture.Stop ();
         if(GetComponent<AudioSource>()) GetComponent<AudioSource>().Stop ();
         currentTime = 0;
         lastCurrentTime = 0;
         if (canFadeOut && fadeOut) {
             fadeCounter = 0;
             alphaStart = alpha;
             isFadingOut = true;
             isFadingIn = false;
         }
     }
     //Pause Button Option
     public void Pause() {
         isPlaying = false;
         movieTexture.Pause ();
         if(GetComponent<AudioSource>()) GetComponent<AudioSource>().Pause ();
     }
     //Play and Pause Button
     public void TooglePlayPause() {
         if (!movieTexture.isReadyToPlay) return;
         if (movieTexture.isPlaying) {
             Pause();
         } else {
             Play();
         }
     }
 
     //Loop Control Toggle Button
     public void Loop() {
 
         //loop = true;
         if(loop) // you can also write if(loop == true)
             loop = false;
         
         else
             loop = true;
         
     }
 

Comment
Add comment · Show 5
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 fafase · Mar 19, 2015 at 01:09 PM 0
Share

Yes, using WWW class and JSON most likely.

avatar image KnightRiderGuy · Mar 19, 2015 at 01:12 PM 0
Share

I'm unfamiliar with "JSON" can you elaborate a little more? Any tutorials on how it's used?

avatar image fafase · Mar 19, 2015 at 01:18 PM 0
Share
 {  "movie": { 
         "name": "$$anonymous$$y$$anonymous$$ovie",
         "length": "122.25",
          "year": 2002
     }
 }

this is a JSON file, basic string with special char at special positions. Using parser like the one from Unify community you can parse that file into a usable object. Depending on the parser ,t eh syntax will change but you would go like:

 WWW www = new WWW(url);
 yield return www;
 string json = www.text;
 JSONObject jsonObject = JSON.Parse(str);
 JSONObject image = jsonObject.GetObject("movie");
 string name = image.GetString("name");


avatar image KnightRiderGuy · Mar 19, 2015 at 01:34 PM 0
Share

Ok Thanks fafase, How would I uses that in something like in my sample script I edited into my question. Is this two different scripts that go on different objects or are these two code snippets combined into one script?

avatar image KnightRiderGuy · Mar 30, 2015 at 02:49 PM 0
Share

Come on SO$$anonymous$$EONE must have a clear and concise answer on this if it is even possible??? fafase posted part of an answer but no follow up. Can the name of a movie in a URL that I am downloading to play as a movie textures name be displayed as UI text or not? And if so how? I'm getting to the point where I am just going to close this question as a CAN't BE DONE?!?

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

MovieTexture.isPlaying 2 Answers

MovieTexture in UI Panel 2 Answers

UI Text to Display Loading Progress of Songs in Music Folder 1 Answer

C# - Play a Video from a Webpage 2 Answers

On movie end 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