Search Unity

Video Simple MovieTextures for Unity WebGL - Null reference and platform not supported exceptions??

Discussion in 'Audio & Video' started by Ploomstar, Mar 16, 2019.

  1. Ploomstar

    Ploomstar

    Joined:
    Apr 15, 2015
    Posts:
    8
    Hello,

    Using Simple MovieTextures for Unity WebGL in Unity 2018.3.8f1
    https://assetstore.unity.com/packag...ts/simple-movietextures-for-unity-webgl-38369

    This used to work perfectly until I updated Unity from 2017 or 2018.1.. can't remember which. I'm being hit with a "platform not supported exception" (despite being set to webgl and within the editor) in addition to a "null reference exception" when trying to play/pause video. I am getting this error even on the sample scene provided within the asset. Building the scene and playing through firefox just shows a black cube instead of a video.

    Is there any work around to let me continue using the simple movietextures? Do I have to rollback to an older Unity version? Appreciate any responses in advance.

    The null reference exception points to lines 18 and 24:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Runtime.InteropServices;
    4.  
    5. public class VideoTest : MonoBehaviour {
    6.  
    7.     WebGLMovieTexture tex;
    8.     public GameObject cube;
    9.  
    10.     void Start () {
    11.         tex = new WebGLMovieTexture("StreamingAssets/Chrome_ImF.mp4");
    12.         cube.GetComponent<MeshRenderer>().material = new Material (Shader.Find("Diffuse"));
    13.         cube.GetComponent<MeshRenderer>().material.mainTexture = tex;
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         tex.Update();
    19.         cube.transform.Rotate (Time.deltaTime * 10, Time.deltaTime * 30, 0);
    20.     }
    21.  
    22.     void OnGUI()
    23.     {
    24.         GUI.enabled = tex.isReady;
    25.        
    26.         GUILayout.BeginHorizontal();
    27.         if (GUILayout.Button("Play"))
    28.             tex.Play();
    29.         if (GUILayout.Button("Pause"))
    30.             tex.Pause();
    31.         tex.loop = GUILayout.Toggle(tex.loop, "Loop");
    32.         GUILayout.EndHorizontal();
    33.  
    34.         var oldT = tex.time;
    35.         var newT = GUILayout.HorizontalSlider (tex.time, 0.0f, tex.duration);
    36.         if (!Mathf.Approximately(oldT, newT))
    37.             tex.Seek(newT);
    38.  
    39.         GUI.enabled = true;
    40.     }
    41. }
    42.  
    and the plugin points to line 43..

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Runtime.InteropServices;
    3. using System;
    4.  
    5. public class WebGLMovieTexture
    6. {
    7. #if UNITY_WEBGL && !UNITY_EDITOR
    8.     [DllImport("__Internal")]
    9.     private static extern int WebGLMovieTextureCreate (string url);
    10.  
    11.     [DllImport("__Internal")]
    12.     private static extern void WebGLMovieTextureUpdate (int video, int texture);
    13.  
    14.     [DllImport("__Internal")]
    15.     private static extern void WebGLMovieTexturePlay (int video);
    16.  
    17.     [DllImport("__Internal")]
    18.     private static extern void WebGLMovieTexturePause (int video);
    19.  
    20.     [DllImport("__Internal")]
    21.     private static extern void WebGLMovieTextureSeek (int video, float time);
    22.  
    23.     [DllImport("__Internal")]
    24.     private static extern void WebGLMovieTextureLoop (int video, bool loop);
    25.  
    26.     [DllImport("__Internal")]
    27.     private static extern int WebGLMovieTextureWidth (int video);
    28.  
    29.     [DllImport("__Internal")]
    30.     private static extern int WebGLMovieTextureHeight (int video);
    31.  
    32.     [DllImport("__Internal")]
    33.     private static extern bool WebGLMovieTextureIsReady (int video);
    34.  
    35.     [DllImport("__Internal")]
    36.     private static extern float WebGLMovieTextureTime (int video);
    37.  
    38.     [DllImport("__Internal")]
    39.     private static extern float WebGLMovieTextureDuration (int video);
    40. #else
    41.     private static int WebGLMovieTextureCreate (string url)
    42.     {
    43.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    44.     }
    45.     private static void WebGLMovieTextureUpdate (int video, int texture)
    46.     {
    47.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    48.     }
    49.     private static void WebGLMovieTexturePlay (int video)
    50.     {
    51.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    52.     }
    53.     private static void WebGLMovieTexturePause (int video)
    54.     {
    55.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    56.     }
    57.     private static void WebGLMovieTextureSeek (int video, float time)
    58.     {
    59.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    60.     }
    61.     private static void WebGLMovieTextureLoop (int video, bool loop)
    62.     {
    63.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    64.     }
    65.     private static int WebGLMovieTextureWidth (int video)
    66.     {
    67.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    68.     }
    69.     private static int WebGLMovieTextureHeight (int video)
    70.     {
    71.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    72.     }
    73.     private static bool WebGLMovieTextureIsReady (int video)
    74.     {
    75.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    76.     }
    77.     private static float WebGLMovieTextureTime (int video)
    78.     {
    79.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    80.     }
    81.     private static float WebGLMovieTextureDuration (int video)
    82.     {
    83.         throw new PlatformNotSupportedException("WebGLMovieTexture is only supported on WebGL.");
    84.     }
    85. #endif
    86.     Texture2D m_Texture;
    87.     int m_Instance;
    88.     bool m_Loop;
    89.  
    90.     public WebGLMovieTexture (string url)
    91.     {
    92.         m_Instance = WebGLMovieTextureCreate(url);
    93.         // We need to Play once to get valid values for height and width.
    94.         Play();
    95.         var width = WebGLMovieTextureWidth(m_Instance);
    96.         var height = WebGLMovieTextureHeight(m_Instance);
    97.         m_Texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
    98.         m_Texture.wrapMode = TextureWrapMode.Clamp;  
    99.         // Pause again, because we don't want to start Playback until explicitly requested.  
    100.         Pause();
    101.     }
    102.  
    103.     public void Update()
    104.     {
    105.         WebGLMovieTextureUpdate(m_Instance, m_Texture.GetNativeTextureID());
    106.     }
    107.  
    108.     public void Play()
    109.     {
    110.         WebGLMovieTexturePlay(m_Instance);
    111.     }
    112.  
    113.     public void Pause()
    114.     {
    115.         WebGLMovieTexturePause(m_Instance);
    116.     }
    117.  
    118.     public void Seek(float t)
    119.     {
    120.         WebGLMovieTextureSeek(m_Instance, t);
    121.     }
    122.  
    123.     public bool loop
    124.     {
    125.         get
    126.         {
    127.             return m_Loop;
    128.         }
    129.         set
    130.         {
    131.             if (value != m_Loop)
    132.             {
    133.                 m_Loop = value;
    134.                 WebGLMovieTextureLoop(m_Instance, m_Loop);
    135.             }
    136.         }
    137.     }
    138.  
    139.     public bool isReady
    140.     {
    141.         get
    142.         {
    143.             return WebGLMovieTextureIsReady(m_Instance);
    144.         }
    145.     }
    146.  
    147.     public float time
    148.     {
    149.         get
    150.         {
    151.             return WebGLMovieTextureTime(m_Instance);
    152.         }
    153.     }
    154.  
    155.     public float duration
    156.     {
    157.         get
    158.         {
    159.             return WebGLMovieTextureDuration(m_Instance);
    160.         }
    161.     }  
    162.  
    163.     static public implicit operator Texture2D(WebGLMovieTexture tex)
    164.     {
    165.         return tex.m_Texture;
    166.     }  
    167. }
    168.