The recommended way to seek time

Hi guys,

I'll try to summarize several questions regarding the time-seek in one post, in order not to spam the forum:

  1. What would be the recommended way to set time with 'VideoPlayer.time'-property? I mean, if the video is playing, should it be paused before setting time and then resumed, or not? Should VideoPlayer.Prepare() be called after setting the new time? If yes, should the preparation be awaited before resuming the video or setting a new time? Should Prepare() be used at all, and what happens if the time is changed in the meanwhile?

  2. Because our video-playing project must work on several platforms, I regularly test the VideoPlayer-component updates (my latest checks were with Unity v5.6.1 though). Setting video time on iOS and MacOSX has no tangible issues, but changing time on Android and Windows (incl. UWP) almost always caused video and audio to unsync. Is this an issue of the VideoPlayer, or is it related to some specifics of the AudioSource-component? What would be the way to work around this issue?

  3. I noticed that sometimes on Windows and Android, when I change the time, both video and audio may remain blocked. The VideoPlayer.time (and frame numer) continues to change, but the frame displayed remains the same and the audio is silent. The video looks like frozen. Any ideas how to work around this case?

By the way, thank you for the great component! Just don't stop its development and bug-fixing.

Hiya.

We just created a tutorial that covers this. The first real tutorial that covers the main properties, methods, and events in the new video player - and how to use them in a real example.

Provide feedback, share, and let us know if we missed anything critical.

https://www.youtube.com/watch?v=ffJoBfj41GU

2 Likes

Have you also issued some audio sync problems after seeking?

Please have a look at this post: https://forum.unity3d.com/threads/video-player-some-mp4-working-some-not.464665/
Post #8.
After seeking the audio on PC gets out of sync

1 Like

I haven't done much unit testing with the audio, but I do know that seeking when playback speed > 1 can cause some unwanted results. Are you doing anything with playback speed with your audio goes out of sync?

Thanks for the fast replay!

My playback speed is set to 1 and won't be set anywhere in my code.

@renaissanceCoder1 Thank you for the tutorial! I find it very useful for VP beginners, and it also gives me many ideas what to improve and what to try next. And of course, I liked it right away ;) As to this tutorial Prepare() should be called only once, when the video is loaded, correct? I currently call it after the time seeks as well, because otherwise, if the video is paused, the picture on screen doesn't change when I do time seek. May that be wrong?

@Knusper Sorry, I missed the other thread regarding the audio going out of sync. This is what I'm experiencing too, especially when time seeks come into play.

I don't think the out-of-sync issue is related to the playback speed. It is platform specific as well. On MacOS X and iOS there are no out-of-sync issues, according to my tests. But on Android, Windows & UWP - the issue is there. This issue could be seen best, if you play a video with a "talking head", like for instance a big part of this video: http://ratemt.com/downloads/sophie-haber2.mp4 It is in German, but this doesn't matter. After 1-2 seeks you can see how the lady's lips get out of sync with what she says.

I also think @DominiqueLrx has already shed some light on audio processing in the other thread, and they are aware of the issue. Maybe it is also due to the fact that audio is processed in the main thread. I hope he could say soon that they have finally fixed the audio issues on these important platforms. I definitely don't want to cause them more stress than needed. In comparison with the initial releases, the VP-component progress is more than visible...

I have written a bug report to unity because I don't know if they are aware of this problem.
I'm just wondering that this issue is still present in the current beta of 2017 (video was introduced in 5.6) because it's not mentioned as experimental release. Something like seeking to a specific time is an essential part of video players.

If no unity representative will answer here, I'll update the status of the bug report as soon as possible.
But a workaround or a estimate when the problem will be solved would be great for me and my contract partners.

Status:
The bugreport has gotten closed because it has already been sent before.
If you haven't voted for the issue i'd suggest to do that to increase the importance of the bug.

The bug report can be found here:
https://issuetracker.unity3d.com/issues/setting-videoplayer-dot-frame-from-code-offsets-audio

Sadly there is no timeframe when the bug will be fixed or if a workaround will be made in the near future. Also it doesn't exist in the current 2017 beta changelog.
Hoping for more information soon.

Best,

Knusper

1 Like

Right away. It is active, as far as I see.

1 Like

Video team is aware of this issue and are working on it.
Android and Windows are mostly affected while OSX and iOS don’t have this effect when using the “direct” audio output mode for all supported formats except webm/vp8 (which use the same desync-causing implementation as Android/Windows).

Unfortunately the fix will not be in 2017.1, but we will try to fix this asap.

4 Likes


That's great news.
What are the chances to get the fixes in a patch release or in 2017.2?

Sorry for the double post.
But as this is an essential feature for a useful video system (which is integrated since months) I need to know if there is any workaround for this issue. The description in bugtracker has a severity of 3 which suggests that a workaround is possible. But I couldn't figure out how. Is this just a misleading message or is there a workaround that hasn't been communicated before?

Best,

Knusper

According to the info I got from @valyard and @DominiqueLrx at Unite, a workaround for the issue may go like this:
"Call Stop(), then Prepare(), wait for prepareCompleted event, then seek, and then Play() may work. The idea is to drain the accumulated audio sample queue before seeking. This is what causes the issue."

So far, my implementation of this workaround was not very successful, but I need to check it once again.

The fix (according to the same info) was planned for Unity 2017.3, i.e. at the end of 2017 or beginning of 2018. I think it is just too late, for fixing such a major video-player issue.

I have also tried this workaround before. But even after following the steps exacly as you described I had no success. 2017.3 is a bit late for a reproduceable and serious bug for such an essential feature. Even because unity is advertizing with that feature :(

We will have to wait now. If you have any sucesses with your workaround, please let me know! :)

Best,

Knusper

@Knusper , FYI: Here is the seek-coroutine I added, according to the workaround instructions above:

    private IEnumerator SeekTimeRoutine()
    {
        videoSeekActive = true;
        videoSeekWasPlaying = isPlaying;

        // do as instructed in the mail from Valentin Simonov & Dominique Leroux (28.06.2017)
        // DominiqueLRX: the idea is to drain the accumulated audio sample queue before seeking
        if (videoPlayer)
        {
            // stop the player
            videoPlayer.Stop();
            if (audioSource)
                audioSource.Stop();
            //isPlaying = false;
            yield return null;

            // prepare the video player
            videoPlayer.Prepare();

            // wait until video is prepared
            Debug.Log("Preparing the video...");

            float waitTillTime = Time.time + 5f;  // wait 5 seconds max
            while (!videoPlayer.isPrepared && (Time.time < waitTillTime))
            {
                yield return null;
            }

            string sMessage = videoPlayer.isPrepared ? "Video prepared" : "Video NOT prepared";
            Debug.Log(sMessage);

            // start playing (otherwise it starts from time/frame 0).
            videoPlayer.Play();
            videoPlayer.Pause();

            yield return null;

            videoPlayer.time = videoSeekTime;
            Debug.Log(string.Format("VideoPlayer time set to: {0:F3}", videoSeekTime));
            videoSeekTime = -1.0;
            //yield return null;
        }

        videoSeekActive = false;
    }

And then in the seek-completed handler, start playing the video:

    void VideoSeekCompleted(VideoPlayer source)
    {
        Debug.Log("Seek completed. Time=" + source.time + ", frame: " + source.frame);

        if(videoSeekWasPlaying)
        {
            videoPlayer.Play();
            if (audioSource)
                audioSource.Play();
            isPlaying = true;
        }
    }

Unfortunately the success is only partial. Sometimes after seek the video and audio start synchronous, but in most cases - not. The video seek time and frame match. I don't know how to get audio frame info, so I could compare.

@DominiqueLrx , could you please comment, and if possible check the code above for errors or provide your own workaround code and more tips. This is a MAJOR bug in the video player, which can ruin our project. I can provide an English-speaking video, if needed.

3 Likes

I've recently tested Beta 2017.3b03.

While the bug tracker still mentions the issue as active, I can say that seeking a video now works as expected without any desynchronization bugs!
Great Job, Unity devs! Now the video player is a full usable tool for me :-)

I left this post just as a small hint to everyone who's running into that issue. I think the thread can be closed once v2017.3 is out in a final stable release.

2 Likes

That it is fixed in the 2017.3b3 is great but we got other weird UI bugs like the RectMask2D that stopped working and the Aspect Ratio fitter that suddenly shoves other unrelated UI content downwards every frame...

We still got to make a bug report for that, but for every bug report, we have to send a slimmed down project which just costs us a lot of time to slim down. We actually wanted to release months ago but with the constant ongoing bugs with Google VR, Video Player and UnityWebRequest on both iOS and Android our project has been delayed for months already waiting for Unity to fix their bugs.
An example is the past few patches and releases contained a UI bug where a button action would be executed multiple times when it contained more than 1 action. like if it contained 3 actions, each action is executed 3 times.
This has been fixed in 2017.3, great but we cannot use an engine that is only in beta. Who knows what other bugs will arise in the meanwhile.
We already made a lot of workarounds in 2017.1 to fix some of the issues. We like to keep the engine up to date but due to the constant bugs the product is in an unreleasable state.
We love using Unity but it would be great if they test the functionality and fix the bugs before actually releasing the features.

Unity could learn from the EasyMovieTexture, the problem with that asset is that it doesn't have streaming and the code base behind it is a huge mess. Atleast the EMT asset has fluent seeking and does not bug out as much.

1 Like

You are particulary right.
I think praising a feature like a whole video system with obvious bugs like not being able to seek without audio delay is not professional. That's something they definitely MUST have known by releasing the feature as final (at least if they have a minimum of QA). Resolving that issue a whole year after it started is a bad joke.

But even if Unity has a lot of bugs it's definitely going better than it was. In times of Unity 4 there were so much bugs that developing complex games were a nightmare. Currently Unity is doing a good job in moving forward to a high quality engine by supporting a lot more platforms than any other engine. It offers a much broader range of features than other engines (XR, mobile performance, cloud networking, cloud builds, ads, just to name a few).

So I think what Unity needs is to still improve it's Quality Assurance. It became a lot better but it seems that features still need more testing (or features must be held back until they are REALLY final)

1 Like

Is your video source a VideoClip or URL? I use URL and the (new) issue I'm facing on 2017.3b3 & b4 is that the audio is not playing at all. If the source is VideoClip, there is no issue. Any experience or suggestions?

My source is a URL as we are streaming our video via StreamingAssets.
Have you tried using an AudioSource instead Direct Audio Output?