unity - Video Controller 비디오 컨트롤러 (Play, Pause, Time Scrub)


Play Mode


1. unity Setting and Cashing


2. Play Button - VideoController.OnButtonPlay Func


3. Pause Button - VideoController.OnButtonPause Func


4. VideoController Slider - VideoController.ChageValue Func


5. Play


C# VideoController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
 
public class VideoController : MonoBehaviour
{
    [SerializeField] RawImage m_rawImage = null;
    [SerializeField] VideoPlayer videoPlayer = null;
    [SerializeField] AudioSource audioSource = null;
    [SerializeField] Slider m_sliderTimeScrub = null;
 
    void Start()
    {
        m_sliderTimeScrub.maxValue = videoPlayer.frameCount;
        StartCoroutine(PlayVideoCor());
    }
 
    private void Update()
    {
        if(videoPlayer.isPlaying == true)
            m_sliderTimeScrub.value = (float)videoPlayer.frame;
    }
 
    IEnumerator PlayVideoCor()
    {
        audioSource.Pause();
 
        videoPlayer.EnableAudioTrack(0true);
        videoPlayer.Prepare();
 
        while (!videoPlayer.isPrepared)
        {
            yield return null;
        }
 
        m_rawImage.texture = videoPlayer.texture;
 
        videoPlayer.Play();
        audioSource.Play();
    }
 
    public void OnClickPlay()
    {
        videoPlayer.Play();
    }
 
    public void OnClickPause()
    {
        videoPlayer.Pause();
    }
 
    public void ChageValue()
    {
        videoPlayer.frame = (long)m_sliderTimeScrub.value;
    }
 
}
 
cs

댓글