• 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 Lotias90 · Aug 18, 2016 at 05:16 AM · androidunity 5iosvideotexturehandheld

Help me step by step to make video play on mobile!

Hello!

I am in a bit of a desperate situation, I am working on a mobile project. As the last step I need to have a button on my canvas (already got that up), when being pressed it plays a video to a user on their phone. The idea is that this will be on Android and iOS. I watched some tutorials online but they did not work on mobile devices.

Then I found out that a script were needed, something like

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayHelp : MonoBehaviour
 {
     public MovieTexture movTexture;
     void Start()
     {
         GetComponent<Renderer>().material.mainTexture = movTexture;
         Handheld.PlayFullScreenMovie("videoname.mp4");
     }
 }

But how do I get it into my scene and working? I am running out of time and I just feel like I have hit a brick wall when im soo close to finishing the project.

I have a button on my Canvas, when it is being pressed it should show this video I got in my stream asset folder, but how?

Please help me and guide me through step by step, what stuff do I need to make and where do I attach each part? directly to the button or do I make the button go to another canvas or an entire new scene? (I would prefer to keep it all in the same scene).

I need to have a video texture I assume, but how do I make one and where do I put it?

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 Lotias90 · Aug 18, 2016 at 02:04 PM 0
Share

Actually I managed to create a RawImage onto my UI which I now managed to link the video.

However I also need the script to make it play, but Im not sure if the script I posted above are correct. If anyone got a full working script for the video to start play when the canvas gets active (linked from a button) please help me :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by skiedude · Aug 18, 2016 at 05:17 PM

Looking at https://docs.unity3d.com/Manual/class-MovieTexture.html, it uses an example when you press the space bar, but I imagine you can change that case to a button press.

 public class PlayMovieOnSpace : MonoBehaviour {
     void Update () {
         if (Input.GetButtonDown ("Jump")) {
             
             Renderer r = GetComponent<Renderer>();
             MovieTexture movie = (MovieTexture)r.material.mainTexture;
             
             if (movie.isPlaying) {
                 movie.Pause();
             }
             else {
                 movie.Play();
             }
         }
     }
 }

Reading a bit above that it says once your movie file is added to your assets it works like a texture.

Once your Movie Texture has been imported, you can attach it to any GameObject or Material, just like a regular Texture.

So sounds like you can just drag it onto your gamecontroller or gameobject (canvas it sounds like in your setup)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Activity Indicator Centered 0 Answers

Accessing the volume buttons on iPhone for some functionality through Unity 1 Answer

Line renderer not smooth 0 Answers

Will movie textures work on iOS and Android phones? Please help...please advice 1 Answer

AdMob in Editor? 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