Search Unity

Video Video Player, play, pause, continue playing from another point...

Discussion in 'Audio & Video' started by Wash3d, Oct 17, 2019.

  1. Wash3d

    Wash3d

    Joined:
    Mar 10, 2015
    Posts:
    6
    Dear Friends,
    I have an issue to solve here, I wrote simple code for play pause a videoplayer and after the video is paused to goto to another point of the video and starts to play. Well everything is OK but to start to play the video after it was paused and goto another specified point touch the button for that even I set myvido.play(), it just goto to another position but doesn´t start to play I need to hit the button again for it starts to play... Could any one help?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5.  
    6. public class PlayVideos : MonoBehaviour
    7. {
    8.     public VideoPlayer vid1;
    9.     public GameObject buton;
    10.     public float segue;
    11.  
    12.     private void Start()
    13.     {
    14.         var frameZero = 0;
    15.         vid1.frame = (long)frameZero;
    16.         vid1.Play();
    17.     }
    18.  
    19.     private void Update()
    20.  
    21.     {
    22.      
    23.         if (vid1.frame == 500)
    24.         {
    25.             vid1.Pause();
    26.         }
    27.         Debug.Log("frame" + vid1.frame);
    28.     }
    29.  
    30.  
    31.     public void acerta()
    32.     {
    33.         var frame = segue;
    34.         vid1.frame = (long)frame;
    35.         vid1.Play();
    36.     }
    37. }
     
  2. Jujika-chile

    Jujika-chile

    Joined:
    Oct 23, 2020
    Posts:
    1
    Because you recive the first frame, i use your code and fix them, and the pause is in the frame 500, but always be in the frame 500 because when you put play automatically enter in the pause, i put 1 more frame when the video is paused.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Video;
    5. public class Controller: MonoBehaviour
    6. {
    7.     public VideoPlayer video;
    8.     public GameObject buton;
    9.     private float segue;
    10.  
    11.     private void Awake()
    12.     {
    13.  
    14.         video = GetComponent<VideoPlayer>();
    15.  
    16.     }
    17.  
    18.     private void Start()
    19.     {
    20.         //var frameZero = 0;
    21.         //vid1.frame = (long)frameZero;
    22.         video.Play();
    23.     }
    24.  
    25.     private void Update()
    26.  
    27.     {
    28.  
    29.  
    30.         if (video.frame == 200)
    31.         {
    32.             video.Pause();
    33.             video.frame = 201;
    34.  
    35.         }
    36.         Debug.Log("frame" + video.frame);
    37.     }
    38.  
    39.  
    40.     public void acerta()
    41.     {
    42.  
    43.  
    44.         //var frame = segue;
    45.         //vid1.frame = (long)frame ;
    46.         video.Play();
    47.     }
    48. }