Has anyone gotten the new Video Player working in WebGL? I’ve tried basically everything under the sun, as well as looking through this forum. It would appear this functionality is bugged to the point of it not working, but I doubt Unity would put out this feature with it being entirely broken. What am I missing? Anyone got a solution?
Bump for support.
I am able to stream the video files from my web server even, but when I upload and test the WebGL build, the VideoPlayer component reverts the back to the sprite renderer that it originally overrides.
Cant get it to work.
I tried to play an MP4 file.
Works fine in android and standalone build.
WebGL:
- Cannot play media. No decoders for requested formats: video/x-ms-wmv
When I transcode to H264 - Cannot play media. No decoders for requested formats: video/x-ms-wmv
When I transcode to VP8 - Nothing happens. Video does not play and there are no errors whatsoever. When I do prepare, the completed event is never triggerd.
It definitely works. We had it working on our end but switched for different reasons to timelines. I did have to go through Unity support at one point because they had a bug … but its definitely been fixed in the official 2017 release. I would poke unity somewhere until you understand what the issue is.
TLDR;
Its been working for us in 2017.1 WebGL.
Hey @DGordon ,
We’re having the same issues as @RavenLiquid . It’s great to hear that you got it working - we’re not sure what we’re missing. Do you by any chance have a small project that is working, and if so, do you mind sharing it with us?
Regarding your video files, did you do anything specific on the codec / encoding that we’re missing? We tried converting our raw video to the mp4 container using both VLC and Premiere and then importing into Unity, and neither one worked. We also played around with all the video import settings in Unity, and none of that worked. I’m wondering if your workflow was different somehow.
Thanks much!
I have it working using file streaming from streaming assets but I had to build the url string using
if (string.IsNullOrEmpty(url))
{
url = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
}
videoPlayer.url = url;
videoPlayer.SetTargetAudioSource(0, audioSource);
Thanks Adam! It looks like your solution is about the best you can get - after more research, apparently the WebGL builds don’t support embedded video, only loading from a URL:
To the Unity folks: you should probably make this glaringly obvious in the docs. This is different from how videos were done previously and different from just about every other type of asset.
Sorry I never responded … I was busy dealing with other WebGL and VideoPlayer bugs. Heh.
Please note: WebGL has a lot of undocumented issues (although we are using it and the final outcome is it works for us), and the VideoPlayer does as well. I suspect the Unity devs are still working their way through various issues. I only got the VideoPlayer working after asking on the forums and having a couple of issues fixed in the 2017 beta (which is as expected). Both of these technologies still have blatant issues that are hopefully being worked on. I’m not complaining that they have issues (I’m glad we have them), but don’t expect everything to always work yet.
For now, you should assume the documentation could be incomplete or blatantly wrong (literally, I came across deprecated code in the 2017.1/2017.2 documentation that crashed WebGL).
It’s getting there … but its really a bit of a minefield right now due to the lack of documentation and official responses (ie: this thread).
I tested this and it works - https://discussions.unity.com/t/662337
Place an htaccess file with the code as described in the link above next to the video on the server
Hi, I have the same issue, can you explain to me how solve this? (I don’t have experience with html or servers, just games running in windows and android). I put the file video in streaming assets, use the URL but not works anyway. Any answer helps. Thx. Below a little of my code:
if ( System.IO.File.Exists (Application.streamingAssetsPath + “/GAMES_TODOS.mp4”)) {
videoPlayer.url = System.IO.Path.Combine (Application.streamingAssetsPath,“GAMES_TODOS.mp4”);
videoPlayer.Prepare ();
videoPlayer.Play ();
Debug.Log (“FileExists”);
}
else{
Debug.Log (“FileDontExists”);
}
EDIT: Works on Editor but when I build a WebGL all components run, less video. Don’t have any error message or something like that.
videoPlayer.url = System.IO.Path.Combine (Application.streamingAssetsPath,“**/**GAMES_TODOS.mp4”);
Slash before video clip name??
First sorry for my english. I go post my solution:
In editor create a folder with the name StreamingAssets and put your video file into then (the video format I uses is .mp4);
script:
Create a VideoPlayer component and assign in a plan case needs video in scene or camera if you need video full screen;
Use this command to combine the streaming assets path with the video file name and extension:
videoPlayer.url = System.IO.Path.Combine (Application.streamingAssetsPath,“myFile.mp4”);
and, call play mode:
videoPlayer.Play();
works fine to me with mp4 and MOV videos! Unity 5.6.5
Thanks for all answers! Helps a lot!
Playing a video directly from StreamingAssets work well for me but I’m trying to download to some kind of web cache system. So, I’m trying to copy a video file to idbfs (IndexedDB) an play it from there without any luck:
IEnumerator RetrieveStreamingAsset(string mediaFileName)
{
string streamingMediaPath = Application.streamingAssetsPath + "/" + mediaFileName;
string persistentPath = Application.persistentDataPath + "/" + mediaFileName;
if (!File.Exists(persistentPath))
{
WWW wwwReader = new WWW(streamingMediaPath);
yield return wwwReader;
if (wwwReader.error != null)
{
Debug.LogError("wwwReader error: " + wwwReader.error);
}
System.IO.File.WriteAllBytes(persistentPath, wwwReader.bytes);
}
video.url = persistentPath;
}
So, the video.url ends pointing to that new location (idbfs/xxxxxxxx/myvideoclip.mp4). But any time I call to video.prepare() I get an 404 not found.
Any idea?
hi, try this way maybe works. I use a public method, no return:
atention with file extension on name;
- public void PlayVideo()
- {
- string streamingMediaPath = System.IO.Path.Combine (Application.streamingAssetsPath,“myFile.mp4”);
video.url = streamingMediaPath;
video.Prepare();
video.Play();
- }
Hi,
Your code works because I tested in my first attempt but I don’t want to do that.
Using your code, everytime you want to play that video it has to be downloaded from an url located in a remote server.
I’m explaining all here (I think it’s better to start a new threat for this problem):
Hi,
In my case the video inside the project was the goal and even this is little hard to make if you never use the streamingassets folder or not have experience with WebGL, servers etc (my case). You try use other url video sample? Maybe the problem is a server permission. (I read this in other post)
Thanks.
Hello, im having issues with Unity 2018.1.0f2 and the VideoPlayer on WebGL, the first video usually plays fine, when i change videos, i can only hear the audio playing but black screen.
void ShowCurrent()
{
Player.url = m_Videos[CurrentPictureIndex];
Player.Prepare();
Player.Play();
}
Maybe you need to call Stop() in the previous videoplayer before Prepare() the next one.
I mean, It seems you are using the same VidepPlayer to play several videos. Make sure you Stop() each video before Prepare() the next one.
It’s the only thing I can think of. Another posibility is to test it in 2017.4.3.
Well, that didn’t fixed it, but gave me a good idea, thank you. Is working fine now.
public void OnDisable()
{
if (Player)
{
Player.Stop();
Player.targetTexture.Release();
Destroy(Player.gameObject);
}
}
private void CreatePlayer()
{
if (Player)
{
Player.Stop();
Player.targetTexture.Release();
Destroy(Player.gameObject);
}
Player = new GameObject().AddComponent();
Player.audioOutputMode = VideoAudioOutputMode.AudioSource;
Player.SetTargetAudioSource(0, audioSource);
Player.renderMode = VideoRenderMode.RenderTexture;
Player.targetTexture = m_texture;
}
void ShowCurrent()
{
CreatePlayer();
Player.url = m_Videos[CurrentPictureIndex];
Player.Prepare();
Player.Play();
}
So, you’re creating a new VideoPlayer each time you play a video, isn’t you? Clever! That way you don’t fix the problem but anyway you find a way to make it work.