Search Unity

Question Change Canvas on VideoPlayer LoopPointReached

Discussion in 'Audio & Video' started by AbePow, Jun 3, 2022.

  1. AbePow

    AbePow

    Joined:
    Jan 3, 2021
    Posts:
    1
    Total Noob/No Code.

    I've built a touchscreen interface for an Android device that plays 3 videos from a looping video menu. I have all the interactions working - press button to play video, press button to return to menu - but I cannot workout how to return to the main menu when a video has finished playing.

    Each videoPlayer is on a Canvas and I am using the onClick functions of buttons to call them up/remove the previous. I have zero code literacy - is there a simple way a poor fool like me can just return to the Menu canvas when a video has reached the end? A simple script on each Canvas component is obvious to me but how to script it is not.
    Interface_WireFrame.jpg
     
  2. Dnalsi

    Dnalsi

    Joined:
    Feb 11, 2014
    Posts:
    9
    Unfortunately, you need to use code for that. You can use this script to do that. Make sure, the file name is VideoPlayerEndReachedEvent like the script.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using UnityEngine.Video;
    4.  
    5. public class VideoPlayerEndReachedEvent : MonoBehaviour
    6. {
    7.     public UnityEvent OnEndReached;
    8.     public VideoPlayer videoPlayer;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         videoPlayer.loopPointReached += VideoPlayer_loopPointReached;
    14.     }
    15.  
    16.     private void VideoPlayer_loopPointReached(VideoPlayer source)
    17.     {
    18.         OnEndReached.Invoke();
    19.     }
    20. }
    21.  
    In the Editor, it should look like this.
    upload_2022-6-6_16-1-40.png