유니티 비디오 플레이어 로컬 재생 Unity Video Player local url

 

1.EasyMovie Texture

 EasyMovie Texture의 경우에는 유니티내에서 임포트해서 비디오클립을 만든영상이면 무리없이 재생이 되는듯 하다.
 하지만 스트리밍 폴더에 넣어놓은 영상을 플레이 할 경우에는 영상이 느려지고, 오디오가 찢어짐.

 이는 영상의 용량이 커지면 더욱심해짐. 따라서 적절하지않음.

 

2. 유니티 내장기능인 Video Player

 URL을 사용하여 스트리밍 폴더에 있는 영상도 재생이 가능한 것을 확인하였음.

 

1
2
3
4
5
6
    public VideoPlayer video;
 
    void Start () {
        video.url = Application.streamingAssetsPath + "/K.mp4";
        video.Play();
    }
cs
 그러나 여러가지 영상을 넣어놓고 스위칭을 해봤을 때 영상에 딜레이가 있는 것을 확인함.
 구체를 3개를 만들어 놓고 videoPlayer를 한개씩 붙여놓은다음,
 상황에 따라서 바로 pause() 실행시키고 구체를 enabled 하는 방식으로 하니 딜레이가 사라짐.
 (메모리는 먹고있겠지만)
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
 
public class MovieManagerMulti : MonoBehaviour {
 
    public enum Language
    {
        kor,
        eng,
        cha
    }
 
    [Header("Primitive")]
    public Language SelectedLanguage;
 
    [Header("Reference")]
    public VideoPlayer videoPlayerK;
    public VideoPlayer videoPlayerE;
    public VideoPlayer videoPlayerC;
 
    public GameObject SphereK;
    public GameObject SphereE;
    public GameObject SphereC;
 
    public string lastInput = "";
 
    void Start ()
    {
        SphereK.SetActive(false);
        SphereE.SetActive(false);
        SphereC.SetActive(false);
 
        videoPlayerK.url = Application.streamingAssetsPath + "/K.mp4";
        videoPlayerE.url = Application.streamingAssetsPath + "/E.mp4";
        videoPlayerC.url = Application.streamingAssetsPath + "/C.mp4";
 
        Cursor.visible = false;
    }
    
    private void Update()
    {
        // 디버깅용 인풋. 각각 k e c 키에 할당함.
        if (Input.GetButton("kor")) {
            if (lastInput == "kor") return;
            StartCoroutine("SetLanguage", Language.kor);
            StartCoroutine("LastInputSet", "kor");
        }
        else if (Input.GetButton("eng"))
        {
            if (lastInput == "eng") return;
            StartCoroutine("SetLanguage", Language.eng);
            StartCoroutine("LastInputSet", "eng");
        }
        else if (Input.GetButton("cha"))
        {
            if (lastInput == "cha") return;
            StartCoroutine("SetLanguage", Language.cha);
            StartCoroutine("LastInputSet", "cha");
        }
        else if (Input.GetButton("escape"))
        {
            if (lastInput == "escape") return;
            Application.Quit();
            StartCoroutine("LastInputSet", "escape");
        }
        else if (Input.GetButton("mousevisible")) // 이건 딜레이 굳이 필요없어보임.
            Cursor.visible = !Cursor.visible;
 
        else if (Input.GetButton("exit"))
        {
            if (lastInput == "exit") return;
 
            videoPlayerK.Pause();
            videoPlayerE.Pause();
            videoPlayerC.Pause();
 
            SphereK.SetActive(false);
            SphereE.SetActive(false);
            SphereC.SetActive(false);
 
            StartCoroutine("LastInputSet", "exit");
        }
    }
 
    IEnumerator LastInputSet(string input)
    {
        lastInput = input;
        yield return new WaitForSeconds(3f);
        if(lastInput == input)
            lastInput = "";
    }
 
    IEnumerator SetLanguage(Language a)
    {
        SelectedLanguage = a;
        
        if (SelectedLanguage == Language.kor)
        {
            Debug.Log("korea");
            SphereK.SetActive(true);
            SphereE.SetActive(false);
            SphereC.SetActive(false);
            videoPlayerK.time = 0f;
            videoPlayerK.Play();
        }
        else if (SelectedLanguage == Language.eng)
        {
            Debug.Log("english");
            SphereK.SetActive(false);
            SphereE.SetActive(true);
            SphereC.SetActive(false);
            videoPlayerE.time = 0f;
            videoPlayerE.Play();
        }
        else if (SelectedLanguage == Language.cha)
        {
            Debug.Log("chinese");
            SphereK.SetActive(false);
            SphereE.SetActive(false);
            SphereC.SetActive(true);
            videoPlayerC.time = 0f;
            videoPlayerC.Play();
        }
        
        yield return new WaitForFixedUpdate();
        Camera.main.transform.rotation = Quaternion.identity;
    }
}
 
cs

 

 

 

이건 렌더 텍스쳐를 활용한 스테레오 영상 재생.

렌더 텍스쳐를 활용한 방식이 첫프레임이 재생전 노출되는 현상이 있다,.

RenderTexture.Release()를 재생 전에 넣어주면 버퍼를 지운다!

 

 

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
 
public class MainControlManager : MonoBehaviour {
 
    public enum Language
    {
        kor,
        eng,
        cha
    }
 
    [Header("Primitive")]
    public Language SelectedLanguage;
 
    [Header("Reference")]
    public TCPManager _TCPManager;
    public GameObject Canvas;
    public VideoPlayer[] allVideoplayer;
 
    public string lastInput = "";
 
    private void Start()
    {
        for (int i = 0; i < allVideoplayer.Length; i++)
        {
            allVideoplayer[i].gameObject.SetActive(false);
        }
 
        allVideoplayer[0].url = Application.streamingAssetsPath + "/KL.mp4";
        allVideoplayer[1].url = Application.streamingAssetsPath + "/KR.mp4";
        allVideoplayer[2].url = Application.streamingAssetsPath + "/EL.mp4";
        allVideoplayer[3].url = Application.streamingAssetsPath + "/ER.mp4";
        allVideoplayer[4].url = Application.streamingAssetsPath + "/CL.mp4";
        allVideoplayer[5].url = Application.streamingAssetsPath + "/CR.mp4";
 
        Cursor.visible = false;
        Canvas.SetActive(false);
    }
    
    private void Update()
    {
 
        // 디버깅용 인풋. 각각 k e c 키에 할당함.
        if (Input.GetButton("kor") || _TCPManager.serverMessage.Equals("korean"))
        {
            if (lastInput == "kor") return;
            StartCoroutine("SetLanguage", Language.kor);
            StartCoroutine("LastInputSet", "kor");
        }
        else if (Input.GetButton("eng") || _TCPManager.serverMessage.Equals("english"))
        {
            if (lastInput == "eng") return;
            StartCoroutine("SetLanguage", Language.eng);
            StartCoroutine("LastInputSet", "eng");
        }
        else if (Input.GetButton("cha") || _TCPManager.serverMessage.Equals("chinese"))
        {
            if (lastInput == "cha") return;
            StartCoroutine("SetLanguage", Language.cha);
            StartCoroutine("LastInputSet", "cha");
        }
        else if (Input.GetButton("escape"))
        {
            if (lastInput == "escape") return;
            Application.Quit();
            StartCoroutine("LastInputSet", "escape");
        }
        else if (Input.GetButton("mousevisible")) // 이건 딜레이 굳이 필요없어보임.
            Cursor.visible = !Cursor.visible;
 
        else if (Input.GetButton("stop") || _TCPManager.serverMessage.Equals("stop"))
        {
            if (lastInput == "stop") return;
 
            for (int i = 0; i < allVideoplayer.Length; i++)
            {
                allVideoplayer[i].Pause();
                allVideoplayer[i].gameObject.SetActive(false);
                allVideoplayer[i].targetTexture.Release();
            }
 
            Canvas.SetActive(false);
            StartCoroutine("LastInputSet", "stop");
        }
    }
 
    IEnumerator LastInputSet(string input)
    {
        lastInput = input;
        yield return new WaitForSeconds(3f);
        if (lastInput == input)
            lastInput = "";
    }
 
    public IEnumerator SetLanguage(Language a)
    {
        _TCPManager.serverMessage = "";
        SelectedLanguage = a;
 
        if (SelectedLanguage == Language.kor)
        {
            Debug.Log("korea");
            mSetPlayVideo(allVideoplayer[0]);
            mSetPlayVideo(allVideoplayer[1]);
            allVideoplayer[2].gameObject.SetActive(false);
            allVideoplayer[3].gameObject.SetActive(false);
            allVideoplayer[4].gameObject.SetActive(false);
            allVideoplayer[5].gameObject.SetActive(false);
 
            yield return new WaitUntil(() => allVideoplayer[0].isPlaying);
            yield return new WaitUntil(() => allVideoplayer[1].isPlaying);
        }
        else if (SelectedLanguage == Language.eng)
        {
            Debug.Log("english");
            mSetPlayVideo(allVideoplayer[2]);
            mSetPlayVideo(allVideoplayer[3]);
            allVideoplayer[0].gameObject.SetActive(false);
            allVideoplayer[1].gameObject.SetActive(false);
            allVideoplayer[4].gameObject.SetActive(false);
            allVideoplayer[5].gameObject.SetActive(false);
 
            yield return new WaitUntil(() => allVideoplayer[2].isPlaying);
            yield return new WaitUntil(() => allVideoplayer[3].isPlaying);
        }
        else if (SelectedLanguage == Language.cha)
        {
            Debug.Log("chinese");
            mSetPlayVideo(allVideoplayer[4]);
            mSetPlayVideo(allVideoplayer[5]);
            allVideoplayer[0].gameObject.SetActive(false);
            allVideoplayer[1].gameObject.SetActive(false);
            allVideoplayer[2].gameObject.SetActive(false);
            allVideoplayer[3].gameObject.SetActive(false);
 
            yield return new WaitUntil(() => allVideoplayer[4].isPlaying);
            yield return new WaitUntil(() => allVideoplayer[5].isPlaying);
        }
 
        Canvas.SetActive(true);
    }
 
    void mSetPlayVideo(VideoPlayer videoplayer)
    {
        videoplayer.targetTexture.Release();
        videoplayer.gameObject.SetActive(true);
        videoplayer.time = 0f;
        videoplayer.Play();
    }
    
}
 
cs

 

 

 

URL에다가 로컬 파일을 재생 시킬 때

 C:/Users/파일명.mp4 이런식으로 맨처음에 아무것도 없이 바로 경로가 나오면 정상작동하는 것을 확인함;

 

 

댓글

Designed by JB FACTORY