6

I have used video player to play video, everything works fine in unity but when I build it and run on firefox or any other browser,the video won't play. I have tried different settings and different video formats but nothing seems to work. I don't get any errors.

I have an empty scene with camera and video player, no scripts. Just used video player and used play on awake to play the video. Works fine in playmode but won't work in webgl build.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Jz Konain
  • 219
  • 1
  • 2
  • 8
  • WebGL does not support MovieTextures. – Draco18s no longer trusts SE Feb 25 '19 at 01:28
  • @Draco18s how to play a video in webgl then ? – Jz Konain Feb 25 '19 at 04:39
  • After Lots of effort and internet research found a solution in the comments. 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(); – Jz Konain Feb 25 '19 at 06:12

1 Answers1

14

In the editor create a folder with the name StreamingAssets and put your video files into that folder. The video format that I used is mp4 . Create a VideoPlayer component and attach it to a gameobject. Reference that component in a script and use the following command

videoPlayer.url = System.IO.Path.Combine (Application.streamingAssetsPath,"myFile.mp4"); 

You can use other videoplayer commands like Video.Play(); to play the video.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Jz Konain
  • 219
  • 1
  • 2
  • 8
  • 1
    I used this solution and now the first frame of my video is showing, but the video doesn't actually play... – Truth Apr 17 '20 at 13:25
  • @Truth did you find a solution to this? – cyo Aug 26 '20 at 16:46
  • It is good solution, thanks. But it is worth to mention that there may also be some additional troubles when trying to play videos in Microsoft Edge browser. In my case I was only able to play videos when I have created local HTTP server in Python and opened WebGL Unity project in Firefox. When I did the same thing earlier on Microsoft Edge browser, I had only black screen and audio playing, but not working video - even after applying this solution in my script. – westman379 Nov 24 '20 at 11:15
  • 1
    @Truth - I ran into this issue in Chrome (after fixing the initial issue this question is about). The issue stems from Chrome refusing to play video/sound without the user first having interacted with the game. My solution was to add a new scene at the start that forces the user to click before continuing onto the "true" starting scene. Hope that helps! – Micah Cowan Feb 12 '21 at 10:05
  • @cyo see the above answer for the first-frame-only problem ^ – Micah Cowan Feb 12 '21 at 10:06
  • @cyo - Ah! Sorry I didn't reply. I actually did come up with a solution to this (a different one), but I don't remember what it was... – Truth Feb 18 '21 at 00:37
  • Hello. I just want to refer to my last comment and the "black screen" issue. I was able to solve this by upgrading project to Unity 2020.2.5f1 and by switching shader types on my materials to "Unlit/Texture" instead of type used by GoogleVR. Now videos are playing fine on all browsers. – westman379 Feb 23 '21 at 12:03