1
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

[RequireComponent (typeof(AudioSource))]

public class PlayVideo : MonoBehaviour {

public MovieTexture movie;
public AudioSource audio;

// Use this for initialization
void Start () {
    GetComponent<RawImage> ().texture = movie as MovieTexture;
    audio = GetComponent<AudioSource> ();
    audio.clip = movie.audioClip;
    movie.Play();
    audio.Play();
}

this script is working when i play. But i get error when i buid for android apk. can i play the video in android device ?

Faza Adhzima
  • 45
  • 1
  • 7

1 Answers1

1

MovieTexture is not supported on Android.

https://docs.unity3d.com/Manual/class-MovieTexture.html

There is the new VideoPlayer coming in 5.6.

https://docs.google.com/document/d/1gZa5z_jEEETDk8E_hbYXXjNhetRlM9eu8eTpbfMkRYY/edit

As for the warning, there was a time when all MonoBehaviour would get a set of reference for other scripts. Rigidbody, AudioSource, Transform,.. all of those Unity types. But it was removed and only Transform made it through the cut (most likely coz it is the only component sure to be found).

Despite the fact it was removed, it seems they forgot to totaly remove the references, so even though they are not available, the warning pops up (maybe the warning debug code check is still there while compiling even though the reference is not existing).

You can ignore, add a macros:

#pragma warning disable 0108

use a different naming or add a new keyword.

private new AudioSource audio;

EDIT: If you need to play video on Androir in 5.5 you can either use:

https://docs.unity3d.com/ScriptReference/Handheld.PlayFullScreenMovie.html

which will play full-screen. It basically pauses the Unity application, starts a new process of a video player that you can stop by tapping on the video. There is no further control and you cannot make the window smaller.

The other case is to purchase a plugin from the store. Just set a search for video texture and do your pick.

In this case, it will use a render texture to display the video content. So you can set the texture on a UI object or a world object.

Everts
  • 10,408
  • 2
  • 34
  • 45