Preface: I have gotten some basic controls working for the new VideoPlayer component, and I have everything working well in the editor. However, when I run the scene on my Android device, I run into some problems.
Main problem: When I play the video (for example for 100 frames), and then set the video player back to frame 50, the video will freeze up for a few seconds. This freeze time increases the farther along you are in the video. (Going from 100 to 50 frames takes 1 sec, going from 5000 to 4000 frames takes 10+ seconds.)
Seeking to a specific frame does eventually work, but takes a long time on Android.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
public class VideoPlayerControl : MonoBehaviour {
[Header("Settings")]
[Range(0.1f, 10f)]
public float playbackSpeed = 1f;
[Header("UI Controls")]
public Slider progressBar;
//Private vars
VideoPlayer vPlayer;
public int vidFrameLength;
bool shouldStartPlaying = true;
// Use this for initialization
void Start () {
vPlayer = gameObject.GetComponent<VideoPlayer>();
vPlayer.playbackSpeed = playbackSpeed;
vPlayer.Prepare();
vidFrameLength = (int)vPlayer.frameCount;
progressBar.maxValue = vidFrameLength;
}
// Update is called once per frame
void Update () {
if(shouldStartPlaying && vPlayer.isPrepared){
Play();
shouldStartPlaying = false;
}
}
public void Play(){
vPlayer.Play();
}
public void Pause(){
vPlayer.Pause();
}
public void Stop(){
vPlayer.Stop();
}
//This is called by the slider (Event Trigger: End Drag)
public void SetFrameBySlider(){
JumpToFrame(progressBar.value);
}
public void JumpToFrame(float frame){
vPlayer.frame = (long)frame;
}
}
Conclusion: If anyone else has tried getting seeking working on Android, and has a better solution or any tips, I’d appreciate it. I’ve seen that some people say that the VideoPlayer is not fully working on Android, but I’m not sure what Unity’s support level is for this feature.
Notes: I’m testing on a Google Pixel (Android 7.1). I am testing with a video that uses all Unity’s recommended specs.