Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug Set VideoPlayer.frame not working after the video is looped

Discussion in 'Audio & Video' started by SRx734, May 5, 2024.

  1. SRx734

    SRx734

    Joined:
    Sep 4, 2018
    Posts:
    10
    I'm setting VideoPlayer.frame to 0 to make a replay function. It works fine if the VideoPlayer is not looping, but if it is and the video has reached loop point once it no longer works. Below is the code I'm using. I've aslo attached some videos to explain the situation.

    Code (CSharp):
    1. #region
    2.  
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5.  
    6. #endregion
    7.  
    8. public class VideoTester : MonoBehaviour
    9. {
    10.     [SerializeField] private VideoPlayer _videoPlayer;
    11.  
    12.     private bool _isSeeking;
    13.  
    14.     private void Update()
    15.     {
    16.         if (Input.GetKeyDown(KeyCode.R))
    17.         {
    18.             print("Hit replay");
    19.            
    20.             Replay();
    21.         }
    22.     }
    23.  
    24.     private void Replay()
    25.     {
    26.         if (_isSeeking)
    27.         {
    28.             return;
    29.         }
    30.        
    31.         print("Replay started");
    32.  
    33.         _isSeeking = true;
    34.  
    35.         _videoPlayer.Pause();
    36.         _videoPlayer.seekCompleted += VideoPlayerOnSeekCompleted;
    37.         _videoPlayer.frame = 0;
    38.     }
    39.  
    40.     private void VideoPlayerOnSeekCompleted(VideoPlayer videoPlayer)
    41.     {
    42.         _videoPlayer.seekCompleted -= VideoPlayerOnSeekCompleted;
    43.        
    44.         _isSeeking = false;
    45.        
    46.         _videoPlayer.Play();
    47.        
    48.         print("Seek Completed");
    49.     }
    50. }
     

    Attached Files: