Can't set VideoPlayer.frame directly on android

Hi, I’m having an issue regarding the VideoPlayer component on Unity2017.1

What I want to do is that I want to seek video to a specific frame. The Play(), Pause() are not suitable for my purpose, because I need to accurately control with respect to frame index.

Here is a simple script I used.
In the editor and iOS I can set VideoPlayer.frame, and video jumps to the specified frame index properly.
But on android, it just won’t work. The video never seek to the frame.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Video;

[RequireComponent(typeof(VideoPlayer))]
public class VideoControl : MonoBehaviour {
    public enum SeekMode{FrameIndex, NormalizedTime}
    [SerializeField] SeekMode mode = SeekMode.NormalizedTime;
    [SerializeField] ulong frameIndex;
    [SerializeField, Range(0,1)] float normalizedTime;
    [SerializeField, Range(0.01f, 0.5f)] float damp = 0.1f;

    //=== PROPERTIES
    public VideoClip Clip{ get{ return video.clip;}}
    public SeekMode Mode { get{ return mode;} set{mode = value;}}
    public float Damp{
        get{ return damp;}
        set{ damp = Mathf.Max(0.01f, Mathf.Min(value, 0.5f));}
    }
    public bool IsVideoPrepared{ get{ return isVideoPrepared;}}
    public ulong FrameCount{ get{ return video.frameCount;}}
    public float FrameRate{ get{ return video.frameRate;}}
    //=== INTERNAL REFERENCES
    VideoPlayer video;

    //=== FLAGS
    bool isVideoPrepared;

    // Use this for initialization
    void Awake () {
        video = GetComponent<VideoPlayer>();
        video.errorReceived += Video_ErrorReceived;
        video.prepareCompleted += Video_PrepareCompleted;
        video.frameDropped += Video_FrameDropped;
        video.Prepare();
        VideoCheck();
    }
    float t;
    float vel;
    // Update is called once per frame
    void Update () {
        if(isVideoPrepared){
            switch(mode){
                case SeekMode.FrameIndex :
                    t = Mathf.SmoothDamp(t, frameIndex, ref vel, damp);
                    video.frame = (long)t;
                    break;
                case SeekMode.NormalizedTime :
                    t = Mathf.SmoothDamp(t, normalizedTime, ref vel, damp);
                    video.time = (t * video.clip.length);
                    break;
            }
        }
    }

    public void SetVideo(VideoClip _clip){
        video.clip = _clip;
        video.Prepare();
        normalizedTime = 0f;
        frameIndex = 0;
        t=0;

        VideoCheck();
    }

    void VideoCheck(){
        Debug.Log("=== Video check ===");
        Debug.Log("canStep : " + video.canStep);
        Debug.Log("canSetTime : " + video.canSetTime);
        Debug.Log("canSetTimeSource : " + video.canSetTimeSource);
        Debug.Log("canSetSkipOnDrop " + video.canSetSkipOnDrop);
        Debug.Log("canSetPlaybackSpeed : " + video.canSetPlaybackSpeed);
        Debug.Log("canSetDirectAudioVolume : " + video.canSetDirectAudioVolume);
    }

    public void SetNormalizedTime(float _0To1){
        normalizedTime = Mathf.Max(0, Mathf.Min(1, _0To1));
    }
    public void SetTargetFrameIndex(ulong _frameIndex){
        frameIndex = _frameIndex >= video.frameCount ? video.frameCount-1 : _frameIndex;
    }

    void Video_ErrorReceived(VideoPlayer source, string message)
    {
        Debug.LogError("Video error : "+source.name+" / "+message);
    }

    void Video_PrepareCompleted(VideoPlayer source)
    {
        Debug.Log("Video preparation completed.");
        isVideoPrepared = true;
    }

    void Video_FrameDropped(VideoPlayer source)
    {
        Debug.LogWarning("Video frame dropped!");
    }
}

You can check the script with a simple slider using SetNormalizedTime(float) as an EventListener.

Also, I tried the VideoPlayer.Pause(). From the Unity Scripting API Reference, Pause() 'Pauses the playback and leaves the current time intact.’ On the Editor and iOS, when the Pause() is called the video frame is fixed to the current time, but on Android it goes back to the first frame (like Stop()).

Nobody is having the issue??

Unity dev team is working on the problem(Unity Issue Tracker - [VideoPlayer] VideoPlayer.frame controlled by the slider doesn&#39;t start video playback)

  • Enabling ‘Multithreaded Rendering’ option on Android causes performance drop on VideoPlayer. VideoPlayer failed to play a video.

A small bump to this issue. I’m currently working on a 360 video using Android and I’m experiencing the same issue.
Interestingly in my case I am able to set the frame property, but only once.

Because the video I’m using is a test video, with the first couple seconds of unrelated content, I’m skipping to frame 350 at the very beginning (before playing). That works. In the video there is a short introduction which can be skipped by the user. If that happens then video is set to frame 1500 and at that point the video freezes.

On a sidenote, when I set the starting frame to 1500 instead of 350, the video also freezes.

Using Unity 5.6.4f1, Android (with cardboard enabled)
My code is pretty much the same as mentioned by NGC6543.
Before setting the frame I’ve also called videoplayer.Stop() and videoplayer.Pause().

I read in a different thread that disabling multi-threaded rendering could help and in my case it did. However this was only the case when the video was Stopped and not Paused.

Hi @Trav3l3r , I ended up using a 3rd party plugin instead. I couldn’t wait until the Unity dev resolve the issue.

Hi, Im also having problems with the Unity video player… which 3rd party plugin did you use? I need one that’s compatible with Android, Mac, PC, and IOS.

Thanks

Hey,
I didn’t expect this issue still exists. I used AVPro plugin. It supports all platform and the performance was good!

Yes the issue exists, Im unable to set the Video frame (seek), even if you write to it and read it back right away, it doesnt change.

AVPro is $450, is this the one you used? I cant afford that!

https://assetstore.unity.com/packages/tools/video/avpro-video-56355

What do you think of this one (a little bit cheaper) but seems it cant play MP4… WHAT!!!

https://assetstore.unity.com/packages/tools/video/ump-pro-android-ios-83283

Well, I’ve never used that one myself. Can’t tell, sorry