Search Unity

Question Unity WebGL Video Player doesn't play on IOS mobile

Discussion in 'Audio & Video' started by TheHonorableFisher, Jul 13, 2020.

  1. TheHonorableFisher

    TheHonorableFisher

    Joined:
    Apr 30, 2020
    Posts:
    4
    Hi, I recently had to make a multi platforme web player, the problem that I encounter is that there is no way to make it work on IOS mobile, the video player just don't want to play the video, it stay on a black screen but the audio is working fine (I manage the audio and the video separately) so I wonder if there is any restriction or requirement that is not mention on the IOS documentation to allow a video to play.
    I've try many thing to make it work like disabling the auto replay and the play on awake function, I also try to only play the video when the user clic or press on a button but it still doesn't work when it work fine on every other platform.
    If somewhone have information or a way to make it work I would appreciate the help.
     
  2. Virat-Gangurde

    Virat-Gangurde

    Joined:
    Aug 20, 2019
    Posts:
    12
    Hi,

    There is problem for videoplayer with WebGL platform. This is bug and Unity working on this and resolved for versions as issue mentioned in below link,
    https://issuetracker.unity3d.com/is...webgl-builds-when-the-video-is-loaded-via-url

    I have checked in 2019.3.15f1 (recommended in issue list solution) , 2019.4.2f1 (LTS), 2019.3.0f6. But it’s not working.

    Kindly let if you get any work around, me too searching same issue solution.

    Thanks,
    Virat
     
  3. PeteS

    PeteS

    Joined:
    Aug 1, 2012
    Posts:
    7
    URL video stream is still not working on ios 13 webgl for me even in 2020.2.0a18. (could be an IOS issues??)
    Videos stream plays in firefox chrome, (chrome android) safari edge browsers.
    For older version of unity I copied over the "video.js" from 2020.2.0a18 to currently used 2014.4.4f1
    ProgramFiles\Unity\Hub\Editor\2019.4.4f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib
    I added on line 11 after video.src = str;
    video.preload = 'auto';
    video.autoload = true;
    This got rid of the "WebGL: INVALID_VALUE: tex(Sub)Image2D" error for me. not a full solution but a start
    Edit: If the video is in streaming assets folder it works on webgl IOS but the front end download is increased and not practical with a lot of videos.
     
    Last edited: Jul 21, 2020
  4. TheHonorableFisher

    TheHonorableFisher

    Joined:
    Apr 30, 2020
    Posts:
    4
    Hi PeteS,

    So I try to add the line you were suggesting but still do nothing on my side, I also try to do this solution that was also propose on the ticket but without succes (also try to combine both of them but doesn't work too).

    For the test purpose I've tryed to play a video with the Video Player Render mode set with three option " Material override ", " API ONLY " and "Camera Near/Far Plan " who just work perfectly fine on every platform except on the WebGL IOS.

    I've try all this solution on Unity 2019.4.3f1 and 2019.3.15.f1, that maybe explain why it doesn't work on my side since you are using 4.4f1 I'm going to try with your version this afternoon and hope that it would work (I will update the post with the results this evening)

    But by any chance can you tell me more about what you use to make it work to see if I can reproduce the "fix" ?

    Update : After some try didn't work ether on 2019.4.4f1 on my side
     
    Last edited: Jul 23, 2020
  5. Virat-Gangurde

    Virat-Gangurde

    Joined:
    Aug 20, 2019
    Posts:
    12
    The video rendering in WebGL build issue resolved at my end. This work in Unity 2019.4 LTS versions.
    Note:- I have observed that mp4 video file rendered in WebGL build (not wmv). If any have other types of file format status please update here.

     
  6. KarloE

    KarloE

    Joined:
    Aug 26, 2013
    Posts:
    175
    Did anyone ever managed to make video player work on ios webgl? Because I cannot seem to find a way to do it. Please let me know if there is a way, I've tried most of the things posted around the forums.
     
  7. iasarmientoj

    iasarmientoj

    Joined:
    Jul 22, 2018
    Posts:
    2
  8. sameel

    sameel

    Joined:
    Dec 4, 2015
    Posts:
    17
    Having the same issue regarding the media player not working on Webgl build playing on iPad
     
  9. pierresusset

    pierresusset

    Joined:
    Feb 7, 2009
    Posts:
    60
    Hello,

    I'm also struggling around the WebGL IOS video playback issue.
    I manage to get a video to play on iOS with the following modifications :
    -First, in the video.js script (under WebGL playback engine), add the following line after the video object creation:
    Code (JavaScript):
    1. video.setAttribute('playsinline', 'playsinline');
    - Then, the video play action must be invoked by a user input on the HTML template. Unfortunately, Gilcat plugin isn't enough. On my side, I use a transparent button on top of the game canvas. This button is activated on demand thanks to a JS call from C# and the action on the button send a message back to the C# script to launch the video.

    You can avoid this second step if the video has no sound and the VideoPlayer audioOutputMode is set to null.

    I hope this can help for your projects and also Unity Team to find a better solution to this problem as soon as possible.
     
    msapcili likes this.
  10. TopBananaShana

    TopBananaShana

    Joined:
    Oct 1, 2020
    Posts:
    3
    Hi, can you explain where/how you accessed the video.js to add this line of code? My videos have no audio and are activated by the player so this would be ideal for me but I don't know which script you're referring to.
     
  11. pierresusset

    pierresusset

    Joined:
    Feb 7, 2009
    Posts:
    60
    nijingtech_DEV and JTSenneker like this.
  12. jojizaidi

    jojizaidi

    Joined:
    Jun 30, 2014
    Posts:
    10
    Hey Pierre,
    Couldn't understand your second part. Can you tell me how you activated an html button from c#. I understand we can send commands to JS but how do you simulate a html button press?
     
  13. pierresusset

    pierresusset

    Joined:
    Feb 7, 2009
    Posts:
    60
    Hi,

    here is a very simple example on the code in Unity. On html side, you can take a look at the source of the link I've shared on my previous post.
     

    Attached Files:

  14. jojizaidi

    jojizaidi

    Joined:
    Jun 30, 2014
    Posts:
    10
  15. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    Nope, no way. This is a browser limitation where there needs to be user interaction to play videos with audio. You can have a start button in the beginning of the experience to unlock the video playback for example. And then at some point later you play the video without the user having to press play.
     
  16. LawlessPlay

    LawlessPlay

    Joined:
    Jan 23, 2018
    Posts:
    1
    I solved the play with audio issue by listening for any click event and playing a silent audio file. My guess is Unity can't get the right permissions from Safari for whatever reason. By playing a silent audio it gives the page the correct permissions and you should be able to play a video with sound. There's my react example. It's pretty crude but it works and there's no need for a play button (although even having a play button didn't work for me).

    React.useEffect(() => {
    window.addEventListener('click', () => {
    if (!silentAudioPlayed.current) {
    audio.play();
    silentAudioPlayed.current = true;
    }
    });
    });

    This is only tested on the Mac Safari. I would hope you'd just need to change the event to a touch event and it would have the same effect. Let me know how you get on.
     
  17. Sakshi_09

    Sakshi_09

    Joined:
    Jul 3, 2020
    Posts:
    8
    Hi pierresusset,

    I am working on Unity Webgl video player demo project. i am having issue of videoplayer that video is not playing on iphone web browsers. i have followed your steps like write code in video.js script and also on html side create a play button then on that button onclick method i have called the playvideofromjs() method.
    after all these steps i am having the issue on iphone browser. i can see blank screen only on iphone browsers, but it is working on android and desktop browsers.

    Do you have any other solution or need to write any code on html file?
     
  18. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    This seems cool, I am not familiar a lot with html, can you share an example?

    I just tried to copy your html but it seems not work, probably because i not understand exatcly what to do
     
    Last edited: Jun 14, 2021
  19. adilaghayev

    adilaghayev

    Joined:
    Feb 5, 2021
    Posts:
    1
    Just tried it on a new iPad Pro, doesn't seem to work.

    To make sure I didn't do something wrong:
    - Added silent audio file in streaming assets
    - Loaded up the file in index
    - Added JS touchstart listener, played the audio
    - Attempt to press an in-game Unity button to play a video - same permission error
     
  20. unisip

    unisip

    Joined:
    Sep 15, 2010
    Posts:
    340
    Bumping this up.

    - I managed to get a video ton play with sound on WebGL/iOS using the user touch trick on a transparent div covering the unity scene.
    - I tried playing a muted video at the start of the scene (iOS is not supposed to block that if there is no user intent), I can see the first image of the video but then it doesn't play. Has anyone managed to get that to work ?

    Digging into this video thing which is a bit of a headache, I tried to implement a video player that would play a sequence of urls automatically.

    On iOS, as long as a player element in the dom gets a touch intent the first time it plays, you can switch to another url on that player element and it will work just fine, so it is feasible to play a list of different videos without issues.

    However, looking at the Video.js file in the Unity PlayBackEngine folder, I can see that Unity recreates a new player element every time you change url in the VideoPlayer component in Unity. The previous one gets destroyed. So everytime you switch url on the VideoPlayer, you need a user touch to get the new video to start.

    I tried to modify the javascript code in that Video.js in order to keep a single instance of a video element and reuse it for several videos (my Unity scene only has one VideoPlayer component so that's an acceptable compromise for my use case). I "almost" got this to work: when I change url on the VideoPlayer component, I can see that the video element in the html page behaves correctly. However, I can't get the texture to refresh in Unity. There is a JS_Video_UpdateToTexture javascript function for that, but it doesn't get called anymore once I switch from the original url on the VideoPlayer. So I'm stuck at that point, and not sure what to do (I don't have access to the videoplayer source code that handles the calls to javascript).

    Has anyone tried to implement a similar use case ?

    In any case, here is a copy of the modified Video.js if anyone is interested in trying something similar.
     

    Attached Files:

    Ikaro88 likes this.
  21. johnpatricki442

    johnpatricki442

    Joined:
    Feb 4, 2022
    Posts:
    1
    I would recommend You will need to check the network use of your iPhone app: Settings > WLAN > Apps Using WLAN & Cellular

    Regards
    John Patrick
     
  22. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    I made an asset to play videos on webgl, it works on Safari as well.
     
    Last edited: Nov 25, 2023
  23. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    how can I see the source of the link you shared?
     
  24. Ikaro88

    Ikaro88

    Joined:
    Jun 6, 2016
    Posts:
    300
    can you share how to create the transparent div covering the unity scene?