├── .gitattributes ├── .gitignore ├── Assets ├── Plugins │ ├── IStreamingVideoPlugin.cs │ ├── NativeStreamingVideoPlugin.cs │ ├── StreamingMovieTexture.cs │ ├── WebGLMovieTexture.cs │ ├── WebGLMovieTexture.jslib │ └── WebGLStreamingVideoPlugin.cs ├── README.txt ├── Sample │ ├── SampleScene.unity │ └── VideoTest.cs ├── StreamingAssets │ ├── Chrome_ImF.mp4 │ ├── small.mp4 │ └── small.ogv ├── movieGuiButtons.cs └── testScene.unity ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ├── README.md ├── UnityVS.UnityStreamingMovieTexture.CSharp.Plugins.csproj ├── UnityVS.UnityStreamingMovieTexture.CSharp.csproj └── UnityVS.UnityStreamingMovieTexture.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | bld/ 16 | [Bb]in/ 17 | [Oo]bj/ 18 | 19 | # Roslyn cache directories 20 | *.ide/ 21 | 22 | # MSTest test Results 23 | [Tt]est[Rr]esult*/ 24 | [Bb]uild[Ll]og.* 25 | 26 | #NUNIT 27 | *.VisualState.xml 28 | TestResult.xml 29 | 30 | # Build Results of an ATL Project 31 | [Dd]ebugPS/ 32 | [Rr]eleasePS/ 33 | dlldata.c 34 | 35 | *_i.c 36 | *_p.c 37 | *_i.h 38 | *.ilk 39 | *.meta 40 | *.obj 41 | *.pch 42 | *.pdb 43 | *.pgc 44 | *.pgd 45 | *.rsp 46 | *.sbr 47 | *.tlb 48 | *.tli 49 | *.tlh 50 | *.tmp 51 | *.tmp_proj 52 | *.log 53 | *.vspscc 54 | *.vssscc 55 | .builds 56 | *.pidb 57 | *.svclog 58 | *.scc 59 | 60 | # Chutzpah Test files 61 | _Chutzpah* 62 | 63 | # Visual C++ cache files 64 | ipch/ 65 | *.aps 66 | *.ncb 67 | *.opensdf 68 | *.sdf 69 | *.cachefile 70 | 71 | # Visual Studio profiler 72 | *.psess 73 | *.vsp 74 | *.vspx 75 | 76 | # TFS 2012 Local Workspace 77 | $tf/ 78 | 79 | # Guidance Automation Toolkit 80 | *.gpState 81 | 82 | # ReSharper is a .NET coding add-in 83 | _ReSharper*/ 84 | *.[Rr]e[Ss]harper 85 | *.DotSettings.user 86 | 87 | # JustCode is a .NET coding addin-in 88 | .JustCode 89 | 90 | # TeamCity is a build add-in 91 | _TeamCity* 92 | 93 | # DotCover is a Code Coverage Tool 94 | *.dotCover 95 | 96 | # NCrunch 97 | _NCrunch_* 98 | .*crunch*.local.xml 99 | 100 | # MightyMoose 101 | *.mm.* 102 | AutoTest.Net/ 103 | 104 | # Web workbench (sass) 105 | .sass-cache/ 106 | 107 | # Installshield output folder 108 | [Ee]xpress/ 109 | 110 | # DocProject is a documentation generator add-in 111 | DocProject/buildhelp/ 112 | DocProject/Help/*.HxT 113 | DocProject/Help/*.HxC 114 | DocProject/Help/*.hhc 115 | DocProject/Help/*.hhk 116 | DocProject/Help/*.hhp 117 | DocProject/Help/Html2 118 | DocProject/Help/html 119 | 120 | # Click-Once directory 121 | publish/ 122 | 123 | # Publish Web Output 124 | *.[Pp]ublish.xml 125 | *.azurePubxml 126 | ## TODO: Comment the next line if you want to checkin your 127 | ## web deploy settings but do note that will include unencrypted 128 | ## passwords 129 | #*.pubxml 130 | 131 | # NuGet Packages Directory 132 | packages/* 133 | ## TODO: If the tool you use requires repositories.config 134 | ## uncomment the next line 135 | #!packages/repositories.config 136 | 137 | # Enable "build/" folder in the NuGet Packages folder since 138 | # NuGet packages use it for MSBuild targets. 139 | # This line needs to be after the ignore of the build folder 140 | # (and the packages folder if the line above has been uncommented) 141 | !packages/build/ 142 | 143 | # Windows Azure Build Output 144 | csx/ 145 | *.build.csdef 146 | 147 | # Windows Store app package directory 148 | AppPackages/ 149 | 150 | # Others 151 | sql/ 152 | *.Cache 153 | ClientBin/ 154 | [Ss]tyle[Cc]op.* 155 | ~$* 156 | *~ 157 | *.dbmdl 158 | *.dbproj.schemaview 159 | *.pfx 160 | *.publishsettings 161 | node_modules/ 162 | 163 | # RIA/Silverlight projects 164 | Generated_Code/ 165 | 166 | # Backup & report files from converting an old project file 167 | # to a newer Visual Studio version. Backup files are not needed, 168 | # because we have git ;-) 169 | _UpgradeReport_Files/ 170 | Backup*/ 171 | UpgradeLog*.XML 172 | UpgradeLog*.htm 173 | 174 | # SQL Server files 175 | *.mdf 176 | *.ldf 177 | 178 | # Business Intelligence projects 179 | *.rdl.data 180 | *.bim.layout 181 | *.bim_*.settings 182 | 183 | # Microsoft Fakes 184 | FakesAssemblies/ 185 | 186 | # LightSwitch generated files 187 | GeneratedArtifacts/ 188 | _Pvt_Extensions/ 189 | ModelManifest.xml 190 | /Library 191 | /Assets/UnityVS/Editor 192 | -------------------------------------------------------------------------------- /Assets/Plugins/IStreamingVideoPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Assets.Plugins 7 | { 8 | public interface IStreamingVideoPlugin 9 | { 10 | string Url { get; set; } 11 | bool IsReadyToPlay { get; } 12 | bool IsPlaying { get; } 13 | void Play(); 14 | void Pause(); 15 | bool IsDone { get; } 16 | StreamingVideoStatus Status { get; } 17 | void Update(); 18 | float Duration { get; } 19 | } 20 | 21 | public enum StreamingVideoStatus 22 | { 23 | Unknown, 24 | Error, 25 | Loading, 26 | ReadyToPlay, 27 | Playing, 28 | Paused, 29 | Done, 30 | Stopped 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Assets/Plugins/NativeStreamingVideoPlugin.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER 4 | namespace Assets.Plugins 5 | { 6 | public class NativeStreamingVideoPlugin : IStreamingVideoPlugin 7 | { 8 | private GameObject _gameObject; 9 | private MovieTexture _movieTexture; 10 | private AudioClip _audioClip; 11 | private WWW _www; 12 | private AudioSource _audioSource; 13 | 14 | public NativeStreamingVideoPlugin(string url, GameObject gameObject) 15 | { 16 | DebugStatus = "Creating WWW for ogv"; 17 | _gameObject = gameObject; 18 | _status = StreamingVideoStatus.Unknown; 19 | _url = url; 20 | var fullyQualifiedUrl = _url.StartsWith("http://") ? _url : Application.streamingAssetsPath + "/" + _url; 21 | Debug.Log("Creating www object with url: " + fullyQualifiedUrl); 22 | _www = new WWW(fullyQualifiedUrl); 23 | _audioSource = _gameObject.GetComponent(); 24 | if (_audioSource == null) 25 | { 26 | _audioSource = _gameObject.AddComponent(); 27 | } 28 | } 29 | 30 | public StreamingVideoStatus Status { get { return _status; } } 31 | private StreamingVideoStatus _status; 32 | 33 | private string _url; 34 | public string Url { get { return _url; } set { _url = value; _status = StreamingVideoStatus.Unknown; } } 35 | 36 | public bool IsReadyToPlay 37 | { 38 | get { return Status == StreamingVideoStatus.ReadyToPlay; } 39 | } 40 | 41 | public bool IsPlaying 42 | { 43 | get { return Status == StreamingVideoStatus.Playing; } 44 | } 45 | 46 | public void Play() 47 | { 48 | _gameObject.GetComponent().material.mainTexture = _movieTexture; 49 | _movieTexture.Play(); 50 | if (_audioClip != null) 51 | { 52 | _audioSource.PlayOneShot(_audioClip); 53 | } 54 | } 55 | 56 | public void Pause() 57 | { 58 | _movieTexture.Pause(); 59 | } 60 | 61 | public bool IsDone 62 | { 63 | get { return Status == StreamingVideoStatus.Done; } 64 | } 65 | 66 | public string DebugStatus 67 | { 68 | get; 69 | private set; 70 | } 71 | 72 | public float Duration { get { return _movieTexture.duration; } } 73 | 74 | public void Update() 75 | { 76 | var prevStatus = _status; 77 | switch (prevStatus) 78 | { 79 | case StreamingVideoStatus.Unknown: 80 | case StreamingVideoStatus.Loading: 81 | if (_www != null) 82 | { 83 | if (_www.error != null) 84 | { 85 | DebugStatus = _www.error; 86 | _status = StreamingVideoStatus.Error; 87 | } 88 | bool movieReady = false; 89 | bool audioReady = true; 90 | if (_www.movie != null && _www.movie.isReadyToPlay) 91 | { 92 | Debug.Log("Movie ready"); 93 | movieReady = true; 94 | } 95 | //if (_www.movie.audioClip != null) 96 | //{ 97 | // Debug.Log("Audio Clip not null"); 98 | // audioReady = false; 99 | // if (_www.movie.audioClip.loadState == AudioDataLoadState.Loaded) 100 | // { 101 | // Debug.Log("Audio Clip Ready"); 102 | // audioReady = true; 103 | // } 104 | //} 105 | if (movieReady && audioReady) 106 | { 107 | Debug.Log("Ready To Play"); 108 | _status = StreamingVideoStatus.ReadyToPlay; 109 | _movieTexture = _www.movie; 110 | _audioClip = _movieTexture.audioClip; 111 | } 112 | else 113 | { 114 | _status = StreamingVideoStatus.Loading; 115 | } 116 | } 117 | break; 118 | case StreamingVideoStatus.ReadyToPlay: 119 | if (_movieTexture.isPlaying) 120 | { 121 | _status = StreamingVideoStatus.Playing; 122 | } 123 | break; 124 | case StreamingVideoStatus.Playing: 125 | if (!_movieTexture.isPlaying) 126 | { 127 | _status = StreamingVideoStatus.Done; 128 | } 129 | break; 130 | } 131 | } 132 | } 133 | } 134 | #endif 135 | -------------------------------------------------------------------------------- /Assets/Plugins/StreamingMovieTexture.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEngine; 7 | 8 | namespace Assets.Plugins 9 | { 10 | public class StreamingMovieTexture : MonoBehaviour 11 | { 12 | public string OgvUrl; 13 | public string Mp4Url; 14 | 15 | private IStreamingVideoPlugin _videoPlugin; 16 | 17 | public bool PlayRequested; 18 | 19 | void Start() 20 | { 21 | if (!string.IsNullOrEmpty(OgvUrl)) 22 | { 23 | UnityEngine.Debug.Log("Creating WWW for ogv"); 24 | 25 | #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER 26 | _videoPlugin = new NativeStreamingVideoPlugin(OgvUrl, gameObject); 27 | #elif UNITY_WEBGL 28 | _videoPlugin = new WebGLStreamingVideoPlugin(OgvUrl); 29 | #endif 30 | } 31 | } 32 | 33 | 34 | void Update() 35 | { 36 | gameObject.transform.Rotate(Time.deltaTime * 10, Time.deltaTime * 30, 0); 37 | 38 | _videoPlugin.Update(); 39 | if (_videoPlugin.IsReadyToPlay && PlayRequested) 40 | { 41 | _videoPlugin.Play(); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Assets/Plugins/WebGLMovieTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Runtime.InteropServices; 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 | m_Texture = new Texture2D(0, 0, TextureFormat.ARGB32, false); 94 | m_Texture.wrapMode = TextureWrapMode.Clamp; 95 | } 96 | 97 | public void Update() 98 | { 99 | var width = WebGLMovieTextureWidth(m_Instance); 100 | var height = WebGLMovieTextureHeight(m_Instance); 101 | if (width != m_Texture.width || height != m_Texture.height) 102 | { 103 | m_Texture.Resize(width, height, TextureFormat.ARGB32, false); 104 | m_Texture.Apply(); 105 | } 106 | WebGLMovieTextureUpdate(m_Instance, m_Texture.GetNativeTextureID()); 107 | } 108 | 109 | public void Play() 110 | { 111 | WebGLMovieTexturePlay(m_Instance); 112 | } 113 | 114 | public void Pause() 115 | { 116 | WebGLMovieTexturePause(m_Instance); 117 | } 118 | 119 | public void Seek(float t) 120 | { 121 | WebGLMovieTextureSeek(m_Instance, t); 122 | } 123 | 124 | public bool loop 125 | { 126 | get 127 | { 128 | return m_Loop; 129 | } 130 | set 131 | { 132 | if (value != m_Loop) 133 | { 134 | m_Loop = value; 135 | WebGLMovieTextureLoop(m_Instance, m_Loop); 136 | } 137 | } 138 | } 139 | 140 | public bool isReady 141 | { 142 | get 143 | { 144 | return WebGLMovieTextureIsReady(m_Instance); 145 | } 146 | } 147 | 148 | public float time 149 | { 150 | get 151 | { 152 | return WebGLMovieTextureTime(m_Instance); 153 | } 154 | } 155 | 156 | public float duration 157 | { 158 | get 159 | { 160 | return WebGLMovieTextureDuration(m_Instance); 161 | } 162 | } 163 | 164 | static public implicit operator Texture2D(WebGLMovieTexture tex) 165 | { 166 | return tex.m_Texture; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Assets/Plugins/WebGLMovieTexture.jslib: -------------------------------------------------------------------------------- 1 | var LibraryWebGLMovieTexture = { 2 | $videoInstances: [], 3 | 4 | WebGLMovieTextureCreate: function(url) 5 | { 6 | var str = Pointer_stringify(url); 7 | var video = document.createElement('video'); 8 | video.style.display = 'none'; 9 | video.src = str; 10 | return videoInstances.push(video) - 1; 11 | }, 12 | 13 | WebGLMovieTextureUpdate: function(video, tex) 14 | { 15 | if (videoInstances[video].paused) 16 | return; 17 | GLctx.bindTexture(GLctx.TEXTURE_2D, GL.textures[tex]); 18 | GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, videoInstances[video]); 19 | }, 20 | 21 | WebGLMovieTexturePlay: function(video) 22 | { 23 | videoInstances[video].play(); 24 | }, 25 | 26 | WebGLMovieTexturePause: function(video) 27 | { 28 | videoInstances[video].pause(); 29 | }, 30 | 31 | WebGLMovieTextureSeek: function(video, time) 32 | { 33 | videoInstances[video].fastSeek(time); 34 | }, 35 | 36 | WebGLMovieTextureLoop: function(video, loop) 37 | { 38 | videoInstances[video].loop = loop; 39 | }, 40 | 41 | WebGLMovieTextureHeight: function(video) 42 | { 43 | return videoInstances[video].videoHeight; 44 | }, 45 | 46 | WebGLMovieTextureWidth: function(video) 47 | { 48 | return videoInstances[video].videoWidth; 49 | }, 50 | 51 | WebGLMovieTextureTime: function(video) 52 | { 53 | return videoInstances[video].currentTime; 54 | }, 55 | 56 | WebGLMovieTextureDuration: function(video) 57 | { 58 | return videoInstances[video].duration; 59 | }, 60 | 61 | WebGLMovieTextureIsReady: function(video) 62 | { 63 | return videoInstances[video].readyState >= videoInstances[video].HAVE_CURRENT_DATA; 64 | } 65 | 66 | }; 67 | autoAddDeps(LibraryWebGLMovieTexture, '$videoInstances'); 68 | mergeInto(LibraryManager.library, LibraryWebGLMovieTexture); 69 | -------------------------------------------------------------------------------- /Assets/Plugins/WebGLStreamingVideoPlugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Assets.Plugins 5 | { 6 | public class WebGLStreamingVideoPlugin : IStreamingVideoPlugin 7 | { 8 | private WebGLMovieTexture _movieTexture; 9 | 10 | public WebGLStreamingVideoPlugin(string url) 11 | { 12 | Url = url; 13 | _movieTexture = new WebGLMovieTexture(url); 14 | _status = StreamingVideoStatus.Unknown; 15 | } 16 | 17 | public string Url 18 | { 19 | get; 20 | set; 21 | } 22 | 23 | public bool IsReadyToPlay 24 | { 25 | get { return _movieTexture.isReady; } 26 | } 27 | 28 | public bool IsPlaying 29 | { 30 | get { return _status == StreamingVideoStatus.Playing; } 31 | } 32 | 33 | public void Play() 34 | { 35 | if (IsReadyToPlay) 36 | { 37 | _movieTexture.Play(); 38 | _status = StreamingVideoStatus.Playing; 39 | } 40 | } 41 | 42 | public void Pause() 43 | { 44 | _movieTexture.Pause(); 45 | _status = StreamingVideoStatus.Paused; 46 | } 47 | 48 | public bool IsDone 49 | { 50 | get { return _status == StreamingVideoStatus.Done; } 51 | } 52 | 53 | private StreamingVideoStatus _status; 54 | public StreamingVideoStatus Status 55 | { 56 | get { return _status; } 57 | } 58 | 59 | public float Duration { get { return _movieTexture.duration; } } 60 | 61 | 62 | public void Update() 63 | { 64 | _movieTexture.Update(); 65 | if (_status < StreamingVideoStatus.ReadyToPlay && IsReadyToPlay) 66 | { 67 | _status = StreamingVideoStatus.ReadyToPlay; 68 | } 69 | if (_status == StreamingVideoStatus.Playing && _movieTexture.time == _movieTexture.duration) 70 | { 71 | _status = StreamingVideoStatus.Done; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/README.txt: -------------------------------------------------------------------------------- 1 | Simple MovieTextures for Unity WebGL 2 | ================================= 3 | 4 | Description 5 | =========== 6 | 7 | This package implements basic support for video playback on textures in Unity WebGL. 8 | 9 | Unity's built-in MovieTexture class is not currently available for the WebGL platform. However, it is simple and efficient to use the browser's built-in html5 video element to render video to a texture instead. This package provides a basic implementation of a MovieTexture class on WebGL using html5 video, with support for basic playback controls (play/pause/seek). 10 | 11 | See the contained VideoTest.cs script for a simple sample of playing back video on a texture with a basic UI allowing playback control. 12 | 13 | Disclaimer 14 | ========== 15 | 16 | This is an unsupported package provided by Unity Technologies for demonstration purposes. 17 | 18 | Manual 19 | ====== 20 | 21 | WebGLMovieTexture.WebGLMovieTexture(string url) 22 | 23 | Creates a WebGLMovieTexture instance to play back the video file located at url. 24 | 25 | 26 | 27 | void WebGLMovieTexture.Update() 28 | 29 | Update the texture contents with the current video feed. 30 | 31 | 32 | 33 | void WebGLMovieTexture.Play() 34 | 35 | Starts playing the video. Check WebGLMovieTexture.isReady first. 36 | 37 | 38 | 39 | void WebGLMovieTexture.Pause() 40 | 41 | Pauses playback. 42 | 43 | 44 | void WebGLMovieTexture.Seek(float t) 45 | 46 | Jump to position t in the video, where t is in seconds from the start of the video. 47 | 48 | 49 | 50 | bool WebGLMovieTexture.loop 51 | 52 | Should the movie loop (writable)? 53 | 54 | 55 | bool WebGLMovieTexture.isReady 56 | 57 | Did we download enough data to start playing back video? 58 | 59 | 60 | 61 | public float time 62 | 63 | Current position in the video in seconds. 64 | 65 | 66 | 67 | public float duration 68 | 69 | Total duration of the video. 70 | 71 | Notes 72 | ===== 73 | 74 | Sample video file Chrome_ImF.mp4 taken from www.html5rocks.com, licensed under Apache license 2.0. -------------------------------------------------------------------------------- /Assets/Sample/SampleScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/Assets/Sample/SampleScene.unity -------------------------------------------------------------------------------- /Assets/Sample/VideoTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public class VideoTest : MonoBehaviour { 6 | 7 | WebGLMovieTexture tex; 8 | GameObject cube; 9 | 10 | void Start () { 11 | tex = new WebGLMovieTexture("StreamingAssets/Chrome_ImF.mp4"); 12 | cube = GameObject.CreatePrimitive (PrimitiveType.Cube); 13 | cube.transform.localScale *= 4; 14 | cube.GetComponent().material = new Material (Shader.Find("Diffuse")); 15 | cube.GetComponent().material.mainTexture = tex; 16 | } 17 | 18 | void Update() 19 | { 20 | tex.Update(); 21 | cube.transform.Rotate (Time.deltaTime * 10, Time.deltaTime * 30, 0); 22 | } 23 | 24 | void OnGUI() 25 | { 26 | GUI.enabled = tex.isReady; 27 | 28 | GUILayout.BeginHorizontal(); 29 | if (GUILayout.Button("Play")) 30 | tex.Play(); 31 | if (GUILayout.Button("Pause")) 32 | tex.Pause(); 33 | tex.loop = GUILayout.Toggle(tex.loop, "Loop"); 34 | GUILayout.EndHorizontal(); 35 | 36 | var oldT = tex.time; 37 | var newT = GUILayout.HorizontalSlider (tex.time, 0.0f, tex.duration); 38 | if (oldT != newT) 39 | tex.Seek(newT); 40 | 41 | GUI.enabled = true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/Chrome_ImF.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/Assets/StreamingAssets/Chrome_ImF.mp4 -------------------------------------------------------------------------------- /Assets/StreamingAssets/small.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/Assets/StreamingAssets/small.mp4 -------------------------------------------------------------------------------- /Assets/StreamingAssets/small.ogv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/Assets/StreamingAssets/small.ogv -------------------------------------------------------------------------------- /Assets/movieGuiButtons.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using Assets.Plugins; 4 | 5 | public class movieGuiButtons : MonoBehaviour { 6 | 7 | // Use this for initialization 8 | void Start () { 9 | 10 | } 11 | 12 | // Update is called once per frame 13 | void Update () { 14 | 15 | } 16 | 17 | void OnGUI() 18 | { 19 | if (GUILayout.Button("Play")) 20 | { 21 | gameObject.GetComponent().PlayRequested = true; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Assets/testScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/Assets/testScene.unity -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.0.0b18 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jtothebell/UnityStreamingMovieTexture/b2ab59db3fee2b679b408d5ac5d7841ed72bcc8b/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityStreamingMovieTexture 2 | a movie texture extension for Unity 3d that adds support for Web GL. Basically just a wrapper around the extisting MovieTexture class and Jonas Echterhoff's web gl movie texture (http://forum.unity3d.com/threads/webgl-invalid_value-teximage2d-no-video.284926/) 3 | -------------------------------------------------------------------------------- /UnityVS.UnityStreamingMovieTexture.CSharp.Plugins.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A} 9 | Library 10 | 11 | Assembly-CSharp-firstpass 12 | 512 13 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | .NETFramework 15 | v3.5 16 | Unity Subset v3.5 17 | 18 | GamePlugins:3 19 | WebGL:20 20 | 5.0.0b18 21 | 22 | 23 | pdbonly 24 | false 25 | Temp\UnityVS_bin\Debug\ 26 | prompt 27 | 4 28 | DEBUG;TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_OBSOLETE_API_UPDATING;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;RENDER_SOFTWARE_CURSOR;UNITY_WEBGL;ENABLE_TEXTUREID_MAP;ENABLE_IL2CPP;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE 29 | 30 | 31 | pdbonly 32 | false 33 | Temp\UnityVS_bin\Release\ 34 | prompt 35 | 4 36 | TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_OBSOLETE_API_UPDATING;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;RENDER_SOFTWARE_CURSOR;UNITY_WEBGL;ENABLE_TEXTUREID_MAP;ENABLE_IL2CPP;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Library\UnityAssemblies\UnityEngine.dll 47 | 48 | 49 | Library\UnityAssemblies\UnityEditor.dll 50 | 51 | 52 | 53 | Library\UnityAssemblies\UnityEngine.UI.dll 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /UnityVS.UnityStreamingMovieTexture.CSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {1C529713-AA78-617B-8B5B-66A099857B14} 9 | Library 10 | 11 | Assembly-CSharp 12 | 512 13 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | .NETFramework 15 | v3.5 16 | Unity Subset v3.5 17 | 18 | Game:1 19 | WebGL:20 20 | 5.0.0b18 21 | 22 | 23 | pdbonly 24 | false 25 | Temp\UnityVS_bin\Debug\ 26 | prompt 27 | 4 28 | DEBUG;TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_OBSOLETE_API_UPDATING;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;RENDER_SOFTWARE_CURSOR;UNITY_WEBGL;ENABLE_TEXTUREID_MAP;ENABLE_IL2CPP;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE 29 | 30 | 31 | pdbonly 32 | false 33 | Temp\UnityVS_bin\Release\ 34 | prompt 35 | 4 36 | TRACE;UNITY_5_0_0;UNITY_5_0;UNITY_5;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_OBSOLETE_API_UPDATING;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;RENDER_SOFTWARE_CURSOR;UNITY_WEBGL;ENABLE_TEXTUREID_MAP;ENABLE_IL2CPP;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Library\UnityAssemblies\UnityEngine.dll 47 | 48 | 49 | Library\UnityAssemblies\UnityEditor.dll 50 | 51 | 52 | 53 | Library\UnityAssemblies\UnityEngine.UI.dll 54 | 55 | 56 | 57 | 58 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A} 59 | UnityVS.UnityStreamingMovieTexture.CSharp.Plugins 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /UnityVS.UnityStreamingMovieTexture.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityVS.UnityStreamingMovieTexture.CSharp.Plugins", "UnityVS.UnityStreamingMovieTexture.CSharp.Plugins.csproj", "{B10A1409-2185-7525-BD99-2D9ABB3AB42A}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityVS.UnityStreamingMovieTexture.CSharp", "UnityVS.UnityStreamingMovieTexture.CSharp.csproj", "{1C529713-AA78-617B-8B5B-66A099857B14}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B10A1409-2185-7525-BD99-2D9ABB3AB42A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {1C529713-AA78-617B-8B5B-66A099857B14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {1C529713-AA78-617B-8B5B-66A099857B14}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {1C529713-AA78-617B-8B5B-66A099857B14}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {1C529713-AA78-617B-8B5B-66A099857B14}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | --------------------------------------------------------------------------------