Search Unity

Video Streaming video loses audio after playing for around 12 seconds

Discussion in 'Audio & Video' started by smarsh25, Aug 5, 2019.

  1. smarsh25

    smarsh25

    Joined:
    Jun 24, 2019
    Posts:
    4
    When using VideoPlayer to stream a video from an URL, the video begins to play successfully, but after about 12 seconds the audio cuts out. The video plays on loop, and the audio plays successfully on any loop after the first play is completed. This tends to happen only with videos of certain lengths, and when viewing from our app on iOS or Android over a cellular connection. We are currently using version 2019.1.12f1

    I am following the suggested manner in the Unity docs, setting the VideoPlayer.url to the video url, calling VideoPlayer.Prepare(), and calling VideoPlayer.play() on the prepareCompleted event.

    I am new to Unity. Could anyone suggest troubleshooting steps, or a technique to ensure the audio is buffered and ready to play?

    Any help / direction is much appreciated. Thanks.
     
    Last edited: Aug 5, 2019
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    112
    Hi!

    This sounds like a bug and not a misuse. The VideoPlayer supports two audio output modes that follow distinct software paths, so it may be worth trying both in case they differ in behaviour and help explaining the issue. These modes are VideoAudioOutputMode.AudioSource and VideoAudioOutputMode.Direct. See https://docs.unity3d.com/ScriptReference/Video.VideoPlayer-audioOutputMode.html

    But fundamentally what you describe should not happen. I suppose on a slow connection, it is expected there will be dropouts, or even complete playback halt. Both platforms you describe are not great at surviving bad network conditions. But having the video keep going and audio stop doesn't make much sense and is probably fixable. Note that there are no buffering controls for the time being, the various implementations are supposed to take a best-effort apparoach but clearly something is missing here.

    So unless you find something obvious on your side (like some forgotten logic you did that would mute the audio in certain circumstances...), I encourage you to log a bug with a small project that reproduces the issue and we'll look into it. If you find it indeed happens on slow/intermittent connections, please describe this condition as precisely as you can and we can try to reproduce this condition as well. You can log a bug via Unity's menu: Help -> Report a Bug...

    Thanks for letting us know, and sorry you're running into this trouble!

    Dominique
    A/V developer at Unity
     
    smarsh25 likes this.
  3. smarsh25

    smarsh25

    Joined:
    Jun 24, 2019
    Posts:
    4
    Thanks for the quick reply, and suggestions. I will try setting audioOutputMode to Direct.

    Also, I have created a simple stand alone project, to isolate and troubleshoot this issue.
    https://github.com/sjm-practice/video-stream
    (this repo contains details about the issue, a problematic video url for streaming, as well as the project source code)

    I'll try the steps you suggested, and post my findings here, or create a bug report.

    Thanks again!!
     
  4. smarsh25

    smarsh25

    Joined:
    Jun 24, 2019
    Posts:
    4
    I have tested setting audioOutputMode to 'Direct' and 'Audio Source', both cases lose audio when streaming the video on iOS using a cellular data connection. The video URL is listed below (also in the test project repo).

    I also tested starting VideoPlayer play, by calling '.Play()' directly and calling from a 'prepareCompleted' callback. Both cases lose audio.

    Note: I did add an 'errorReceived' callback, and occasionally get the following error...

    Player having difficulty streaming video "https://avoinsights.com/dashboard/uploads/videos/46070F26-706A-467D-B800-D22584942A0F.mp4"


    Audio loss does still occur, even when not receiving that error. I will do a little more testing and create a bug report. Any suggestions welcome in the meantime (e.g. waiting, advancing over the video, buffering or download strategies / techniques).

    Thanks!

    Side note: I have also tried setting the frame towards the end of the video, stepForward for a bit, then setting frame back to zero and start play from the beginning. No luck. The only success I've had, is stepForward through the whole video, then start play from the beginning. Audio was not lost in that case, but the delay is too long for the user to wait.
     
  5. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    112
    Hi again!

    Thanks for the detailed info. Having this automatic behaviour on the iOS side doesn't surprise me: the lower-level Apple API we're using is making some efforts to make "degraded" playback more comfortable for the user. Maybe it concludes that having audio that constantly starts/stops will not be a good user experience. When we dig into the problem scenario, I'll know more.

    In the mean time, maybe you can consider using a version of the video with a lower resolution when you detect that the network connection is using cellular (not sure how to do this specifically, but you get the idea). This would also not cover the cases where someone moves from wi-fi to cellular during playback, but I'm trying solutions that work with the current state of things.

    You were also saying that Android had audio cutoff while video keeps going. This one is more puzzling to me as I know its implementation isn't as high-level as the iOS one, so from what I know of it, it should either keep going with the stutters, or stall completely (but not continue with video-only). I'd be interested in details about this if you have any; you can provide these with the bug report you create (that's the way to go to have the QA team jump in to help with repro and so on...).

    Dominique
     
    smarsh25 likes this.
  6. smarsh25

    smarsh25

    Joined:
    Jun 24, 2019
    Posts:
    4
    Thanks for the additional suggestions, and quick reply!

    I know that playback issues have occurred on Android, but don't know the specific behavior. I've only received some general reports from users, and haven't tested Android personally. (I tested iOS personally)

    I'll try to collect more details regarding Android when submitting the bug report.

    Thanks. Steve.