RenderHeads / UnityPlugin-AVProVideo

AVPro Video is a multi-platform Unity plugin for advanced video playback
https://www.renderheads.com/products/avpro-video/
238 stars 29 forks source link

Best way to do fastfoward/ rewind #1373

Closed ghost closed 1 year ago

ghost commented 1 year ago

Platforms:

AVPro: v2.6.5

I'm adding additional video navigation into our VR videos. Skip forward/back 10 secs, and FF/ RR.

To define what I mean by FF/RR is: Hold the button and the video moves in that direction at an increased speed (like old VHS players used to).

I'm currently doing this, and it works great on Android.

public void SpeedSeek(bool forward)
    {
        if (_isSeeking) { return; }

        if (_mediaPlayer && _mediaPlayer.Control != null)
        {
            _isSeeking = true;
            double sliderVale = forward ? 0.15 : -0.15;
            TimeRanges bufferedRange = _mediaPlayer.Control.GetBufferedTimes();
            double seekTo = _mediaPlayer.Control.GetCurrentTime() + sliderVale;
#if UNITY_EDITOR
            if (seekTo > bufferedRange.MinTime && seekTo < bufferedRange.MaxTime)
            {
                                sliderVale = forward ? 10 : -10;
                seekTo = _mediaPlayer.Control.GetCurrentTime() + sliderVale;
            }
#endif          
            _mediaPlayer.Control.SeekFast(seekTo);
        }

        _isSeeking = false;
    }

However, on iOS I'm having trouble getting it to work the same.

I've tried using Seek(), SeekFast(), SeekWithTolerance().

Is what I'm trying to do possible? Or do I need to implement this some completely different way?

Chris-RH commented 1 year ago

What sort of media are you trying to do this with and what is the media source?

Have you read our section on seeking and playback rate? https://www.renderheads.com/content/docs/AVProVideo/articles/feature-seeking-playbackrate.html

ghost commented 1 year ago

Yep, I've been through that link.

HLSL, 360 streamed video

Chris-RH commented 1 year ago

You would be better off changing the playback rate for fast-forwarding and rewinding.

ghost commented 1 year ago

The first thing I tried was changing the playbackrate, forward +2 was fine.. but -2 for reverse wasn't - IIRC it just paused and didn't move the timeline backwards.

Chris-RH commented 1 year ago

Did you try -1? Is your video encoded with B-frames?

ghost commented 1 year ago

I didn't try -1, it would be too slow and I assumed a negative playbackrate wouldn't work properly - the AVPro docs say it's generally not recommended to use anyway.

Unfortunately I've no idea if we have B-frames.

Unless this is a very bad way to do it for some reason, I've got something working for both platforms that I'm happy with.

public void SpeedSeek(bool forward)
    {
        if (_isSeeking) { return; }
#if UNITY_IOS
        RegisterMediaPlayerEvents(true);
#endif
        if (_mediaPlayer && _mediaPlayer.Control != null)
        {
            _isSeeking = true;
            double sliderValue = forward ? 0.15 : -0.15;
            TimeRanges bufferedRange = _mediaPlayer.Control.GetBufferedTimes();
            double seekTo = _mediaPlayer.Control.GetCurrentTime() + sliderValue;
#if UNITY_EDITOR || UNITY_IOS
            if (seekTo > bufferedRange.MinTime && seekTo < bufferedRange.MaxTime)
            {
            #if UNITY_EDITOR
                sliderValue = forward ? 10 : -10;
            #elif UNITY_IOS
                sliderValue = forward ? 4 : -4;
            #endif
                seekTo = _mediaPlayer.Control.GetCurrentTime() + sliderValue;
            }
#endif          
            double time = seekTo;
#if UNITY_ANDROID
            _mediaPlayer.Control.SeekFast(time);
            _isSeeking = false;
#elif UNITY_IOS
            _mediaPlayer.Control.Seek(time);
#endif
        }
    }

on iOS _isSeeking is set to false with the media event

Chris-RH commented 1 year ago

Yeah, it can be a bit tricky with HLS, so if its working for you then I'd stick with it.

ghost commented 1 year ago

Great, thanks for the help!