- Home /
how to play video on android
hello guys, i need help here. i want to play video on my android device, i already use many way to achieve that, but no success at all.
this the way i already try :
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(AudioListener))]
public class Movie : MonoBehaviour {
public MovieTexture movie;
private float movieTimer;
void OnGUI(){
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), movie);
movie.Play();
if(movie.duration < movieTimer){
movie.Stop();
print("Movie Finish");
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
movieTimer += Time.deltaTime;
}
}
this don't work because android not support MovieTexture
void Start () { StartCoroutine(PlayMovie()); }
protected IEnumerator PlayMovie(){ Handheld.PlayFullScreenMovie("movie1.avi", Color.blue, FullScreenMovieControlMode.CancelOnInput); yield return new WaitForSeconds(2.0f); print ("Move Scene"); }
My step : - create new C# script and use above code - create empty game object and then attach the script into game object
i don't know why this don't work, but the video not play
IEnumerator Start()
{
Handheld.PlayFullScreenMovie("movie1.avi", Color.blue, FullScreenMovieControlMode.CancelOnInput);
yield return null;
print ("Move Scene");
}
My step : + create new C# script and use above code + create empty game object and then attach the script into game object
this is the last one and not work too, i'm really confused why this code don't work..
sorry it's already work, i made a mistake because use avi format not mp4, after i change into mp4 it's work..
but i have get some problem here, the video not played in full screen and before the video play there will be blank screen maybe 1 or 2 seconds.
anyone can help me to solve this? i used the second and third code both work properly but not full screen and have blank screen for 1 or 2 second..
Thanks before
Where do you load your video ? In a new scene ? Is the scene empty ? Do you want a loading screen or a black screen ?
For the fullscreen thing : what is the resolution of the screen device and the resolution of your video ? In my experience the video doesn't stretch in order to fit the screen device.
ya, i have 1 scene to play the movie and the name is $$anonymous$$ovie.scene.
in $$anonymous$$ovie.scene, i have camera and empty game object attach with $$anonymous$$ovie.cs, the code is :
void Start () { StartCoroutine(Play$$anonymous$$ovie()); }
protected IEnumerator Play$$anonymous$$ovie(){
Handheld.PlayFullScreen$$anonymous$$ovie("movie1.mp4", Color.blue, FullScreen$$anonymous$$ovieControl$$anonymous$$ode.Hidden);
yield return new WaitForSeconds(1.0f);
Application.LoadLevel("City");
}
so the problem is, before the video play, i'll see background color that set by camera for maybe 1-2 seconds.
when the video play, not full screen so in left and right there will be a color that i set in parameter 2, in this case Color.blue.
my devices is Samsung galaxy wonder, and my video resolution is 640 x 480, can i make the resolution more than this?
sorry what's loading screen or black screen?
Thanks for your reply :D
Your device has a 800x480 resolution so it's normal to have borders on the left and on the right. If you want a fullscreen on this specific device you must have a 800x480 video. But keep in $$anonymous$$d this particular resolution will not fit with other devices.
For the loading screen/black screen it was what you wanted. You can set the camera background in black in order to have a black screen before the video (or blue in order to fit with your movie). The loading screen is the same idea except you have to render an image in front of your camera. It's your choice actually.
I'm not sure but you'll not avoid the 1-2 seconds look on the scene because it's the time for the device to load your video. It can be faster with faster devices I guess.
oh, i got it now, i think the video will fit to screen, but i'm wrong at all..
wow, that's a nice idea so just like loading before the video played, ok ok..
thanks for your reply it's really help me here, i'll try to change it and then give the result here :D
Answer by pratam13 · Dec 14, 2016 at 02:07 PM
hey can you help me ? Can you show a complete tutorial on video for android
Your answer
Follow this Question
Related Questions
why cannot build movie texture on android? 4 Answers
Movies on Android. Is it possible? 2 Answers
Movie/Video Texture 0 Answers
IphoneUtils.PlayMovie for Android 1 Answer