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 Nanashi91 · Oct 05, 2012 at 02:55 PM · c#guitexturemovietextureurl

C# - Play a Video from a Webpage

Hello,

I´m trying to play a video from a webpage. I tried to do it with a MovieTexture through creating a plane, giving a guiTexture to it and giving it the following script:

 using UnityEngine;
 using System.Collections;
 
 public class ViewStream : MonoBehaviour {
     
     GameObject myGameObject;
     
     public WWW wwwData;
     public string url = "http://www.youtube.com/watch?v=tkwwrTW7BQU&feature=g-vrec";
     
     // Use this for initialization
     void Start () {
         wwwData = new WWW(url);
         //guiTexture.texture = wwwData.movie;
         renderer.material.mainTexture = wwwData.movie;
     }
     
     // Update is called once per frame
     void Update () {
         
             
             //MovieTexture m = guiTexture.texture as MovieTexture;
             MovieTexture m = renderer.material.mainTexture as MovieTexture;
             
             if(m.isReadyToPlay==true){
                 print ("ready to play");
             }else{
                 print ("not ready to play");
             }
             
             if (!m.isPlaying && m.isReadyToPlay){
                 m.Play();
             }
         
     }
 }

First I tried it with the guiTexture. After it didn´t work I tried to use the main material to play it. But this failed also. In the log is written "not ready to play" all the time.

Can anyone tell me what I´m doing wrong? Does the video file need to have a special format, is my URL not correct or anything else?

Thank you in advance.

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 Graham-Dunnett · Oct 05, 2012 at 08:31 PM

Just use the documentation... The example for WWW.movie does what you want.

http://docs.unity3d.com/Documentation/ScriptReference/WWW-movie.html

What you are doing wrong (I am guessing) is YouTube is not giving you an Ogg movie, so it's never ready to play.

Comment
Add comment · Show 4 · 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 Nanashi91 · Oct 08, 2012 at 09:04 AM 0
Share

Hello,

thank you for your response. Now I´m able to load and play the example video of Unity. But I still have a problem. I´m using a while loop to say if the video is not ready to play unity should wait for some seconds and then check again. The problem is even if the video is not loaded completely Unity recognizes that a part of the video is already ready to play. So he starts playing the video until the unloaded point. When he reaches the unloaded point in the video then he is crashing.

Do you know a way to wait until the video is loaded completely?

$$anonymous$$y while loop looks like that:

[code]

void Start () {

wwwData = new WWW(url);

$$anonymous$$ovieTexture m = wwwData.movie;

while (!m.isReadyToPlay){

StartCoroutine(WaitAndPrint(50.0F));

}

//...

}

IEnumerator WaitAndPrint(float waitTime) {

 yield return new WaitForSeconds(waitTime);

 print("WaitAndPrint " + Time.time);    

}

[/code]

avatar image Zero55 · Feb 22, 2013 at 04:38 AM 0
Share

Try this:

void Start(){

StartCoroutine(StartVideo());

}

IEnumerator StartVideo() {

wwwData = new WWW(url);

yield return wwwData;

$$anonymous$$ovieTexture m = wwwData.movie;

while (!m.isReadyToPlay){

print("WaitAndPrint " + Time.time);

}

}

avatar image jluisaries · Jan 18, 2017 at 03:05 PM 0
Share

Hi Nanashi91, I see that you could play videos from the youtube web, I want to ask you in the end how did you do it? Because I have the same problem and here only you have placed that you succeeded, if you could help I would thank you very much, please

avatar image Bunny83 jluisaries · Jan 18, 2017 at 04:37 PM 0
Share

Have you read the answer? You can not play Youtube videos as Youtube actually streams it in chunks in their own format. Youtube doesn't offer the videos as "single file downloads".

Besides that the Youtube GTCs (general terms and conditions) do not allow this use:

4) A:

You agree not to distribute in any medium any part of the Service or the Content without YouTube's prior written authorization, unless YouTube makes available the means for such distribution through functionality offered by the Service (such as the Embeddable Player).

4) C:

You agree not to access Content through any technology or means other than the video playback pages of the Service itself, the Embeddable Player, or other explicitly authorized means YouTube may designate.

If you try to load / display videos manually from Youture you would violating their terms of service. So it's legally not allowed to do so, even when it was possible.

avatar image
0

Answer by Zero55 · Feb 22, 2013 at 12:18 PM

Unity only supports .ogv and .ogg as video and audio format for the web player.

Try this link to download your youtube video as .MP4 http://www.youtubeinmp4.com

and then go to this link to convert and download the video.

http://video.online-convert.com/convert-to-ogg

Have fun!

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

13 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Detect Collision between two Guitextures or Guitexts etc. 1 Answer

Touch Manager not accepting GUITexture 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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