Search Unity

Video Seeking Performance Delay On Android

Discussion in 'Audio & Video' started by Bandit-Development, May 11, 2017.

  1. Bandit-Development

    Bandit-Development

    Joined:
    Dec 8, 2014
    Posts:
    7
    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:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5. using UnityEngine.UI;
    6.  
    7. public class VideoPlayerControl : MonoBehaviour {
    8.  
    9.     [Header("Settings")]
    10.     [Range(0.1f, 10f)]
    11.     public float playbackSpeed = 1f;
    12.  
    13.     [Header("UI Controls")]
    14.     public Slider progressBar;
    15.  
    16.     //Private vars
    17.     VideoPlayer vPlayer;
    18.     public int vidFrameLength;
    19.     bool shouldStartPlaying = true;
    20.  
    21.     // Use this for initialization
    22.     void Start () {
    23.         vPlayer = gameObject.GetComponent<VideoPlayer>();
    24.  
    25.         vPlayer.playbackSpeed = playbackSpeed;
    26.         vPlayer.Prepare();
    27.         vidFrameLength = (int)vPlayer.frameCount;
    28.  
    29.         progressBar.maxValue = vidFrameLength;
    30.     }
    31.  
    32.     // Update is called once per frame
    33.     void Update () {
    34.         if(shouldStartPlaying && vPlayer.isPrepared){
    35.             Play();
    36.             shouldStartPlaying = false;
    37.         }
    38.     }
    39.  
    40.     public void Play(){
    41.         vPlayer.Play();
    42.     }
    43.  
    44.     public void Pause(){
    45.         vPlayer.Pause();
    46.     }
    47.  
    48.     public void Stop(){
    49.         vPlayer.Stop();
    50.     }
    51.  
    52. //This is called by the slider (Event Trigger: End Drag)
    53.     public void SetFrameBySlider(){
    54.         JumpToFrame(progressBar.value);
    55.     }
    56.  
    57.     public void JumpToFrame(float frame){
    58.         vPlayer.frame = (long)frame;
    59.     }
    60. }
    61.  
    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.
     
  2. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    We had some success with Seek by going to the latest Unity 2017. Ours was totally freezing and now it works well.
     
    Bandit-Development likes this.
  3. Bandit-Development

    Bandit-Development

    Joined:
    Dec 8, 2014
    Posts:
    7
    Are you testing on Android? Also, what beta are you on? I tested again in 2017.1.0b6 and it's still present.
     
    Last edited: May 24, 2017
  4. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    @Bandit-Development
    We have been seeing changes on every beta release. Just today we had to update to 0b7 because one device was super choppy on search. Now we have a search that seems to work on most of our devices. Id do that first.

    Are you sure your codec is the right one for android? It's been sensitive to that too. How long is the video?
     
    Bandit-Development likes this.
  5. Bandit-Development

    Bandit-Development

    Joined:
    Dec 8, 2014
    Posts:
    7
    I updated to Unity 2017.1.0b7, made sure my video was using Unity's advised specs, and I'm still experiencing delayed seeking and frame control.

    Currently, my video is 1:40 long, 1280x666, H264 codec. What settings do you have for your video?
     
  6. AquaGhost

    AquaGhost

    Joined:
    Jan 27, 2013
    Posts:
    94
    Sorry @Bandit-Development , missed your post. Did you fix it?
     
  7. Bandit-Development

    Bandit-Development

    Joined:
    Dec 8, 2014
    Posts:
    7
    @AquaGhost Not really, tried on beta 10 and it's still present. However, I'm running into bugs on iOS and Mac too, so think I'm going to use a custom video asset solution.

    Thanks for your help and info.
     
  8. Cris-Uy

    Cris-Uy

    Joined:
    Oct 28, 2014
    Posts:
    3
    I'm also having the same problem. Though the problem only exist in Android and works perfectly in iOS.

    iOS -> .mov/.mp4 works fine
    Android -> .mov/.mp4 not fine...
     
  9. budhiug

    budhiug

    Joined:
    May 7, 2018
    Posts:
    1
    sorry guys, have you found the solution?