Search Unity

Video Detecting buffering when streaming from URL using VideoPlayer

Discussion in 'Audio & Video' started by pequodification, Apr 26, 2018.

  1. pequodification

    pequodification

    Joined:
    Nov 8, 2016
    Posts:
    2
    I'm trying to stream videos from a remote server using the VideoPlayer component on Android devices. Has anyone had any luck detecting when the VideoPlayer has run out of buffered video?

    I've tried checking whether VideoPlayer.time or VideoPlayer.frame are still being incremented, however these continue to go up even when the video has frozen.

    Any other suggestions?

    (I'm using Unity 2017.4.0f1 on MacOS)
     
  2. musoufan91

    musoufan91

    Joined:
    Nov 27, 2012
    Posts:
    8
    I am going to bump this as I am running into this as well with longer videos.
     
  3. chichilatte

    chichilatte

    Joined:
    May 23, 2018
    Posts:
    1
    Would love an answer to this too (same version as the OP)
     
  4. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    Any answer? Really really need to know how to do this.
     
  5. Briner

    Briner

    Joined:
    Jul 8, 2015
    Posts:
    25
    I just faced this issue and don't find any documentation about how to handle so I found a solution for this by myself:

    Code (CSharp):
    1.  private void Update()
    2.     {
    3.         //when the video is playing, check each time that the video image get update based in the video's frame rate
    4.         if (videoPlayer.isPlaying && (Time.frameCount % (int)(videoPlayer.frameRate + 1)) == 0)
    5.         {
    6.             //if the video time is the same as the previous check, that means it's buffering cuz the video is Playing.
    7.             if (lastTimePlayed == videoPlayer.time)//buffering
    8.             {
    9.                 Debug.Log("buffering");
    10.             }
    11.             else//not buffering
    12.             {
    13.                 Debug.Log("Not buffering");
    14.             }
    15.             lastTimePlayed = videoPlayer.time;
    16.         }
    17.     }
     
  6. Midiphony-panda

    Midiphony-panda

    Joined:
    Feb 10, 2020
    Posts:
    243
    Bump

    Thanks for the workaround @Briner but a proper stalling event from Unity's VideoPlayer feels necessary.
     
    mcbauer, morhun_EP and ShantiB95 like this.
  7. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    524
    Almost 2 years later and this is still an issue.

    Video loaded from a url is "prepared", but when you go to play it, it begins buffering. What is the point of preparing the video?
     
  8. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    We agree with everyone that the control over the buffering is quite lacking, and it is something we want to improve. I added everyone's feedbacks to our product board and should help make this a reality.

    For your question @mcbauer, isPrepared mean 1) the content description has been read and 2) there is enough decoded content to start. So depending on the network condition, the VideoPlayer could start buffering. What you could do is, just after isPrepared, wait an amount of time depending on the video bitrate. And while playing, you can use @Briner solution to do the same when buffering. It should minimize the risk of a hiccup while watching a video.
     
    mcbauer and emerge-sjh like this.
  9. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    524
    Thanks for responding @The_Island I discovered my issue had to do with the H.264 error about the clip not being on the baseline...or whatever. That error apparently caused the video player to struggle with playing the clip correctly. I got a different version of the clip--without that error and everything played perfectly.

    I'm a fan of the video player component now :D.