- Home /
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?
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 :)
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)