| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Components.Video.Plugin; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public class VideoPluginWrapper_Native : IVideoPluginWrapper |
| | 7 | | { |
| 0 | 8 | | private Dictionary<string, DCLVideoPlayer> videoPlayers = new Dictionary<string, DCLVideoPlayer>(); |
| | 9 | |
|
| | 10 | | public void Create(string id, string url, bool useHls) |
| | 11 | | { |
| 0 | 12 | | videoPlayers.Add(id, new DCLVideoPlayer(url)); |
| 0 | 13 | | } |
| | 14 | |
|
| | 15 | | public void Create(string id, string url, VideoType videoType) |
| | 16 | | { |
| 0 | 17 | | Create(id, url, videoType == VideoType.Hls); |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public void Remove(string id) |
| | 21 | | { |
| 0 | 22 | | videoPlayers[id].Dispose(); |
| 0 | 23 | | videoPlayers.Remove(id); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | public void TextureUpdate(string id) |
| | 27 | | { |
| 0 | 28 | | videoPlayers[id].UpdateVideoTexture(); |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | public Texture2D PrepareTexture(string id) |
| | 32 | | { |
| 0 | 33 | | videoPlayers[id].PrepareTexture(); |
| 0 | 34 | | return videoPlayers[id].GetTexture(); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | public void Play(string id, float startTime) |
| | 38 | | { |
| 0 | 39 | | videoPlayers[id].Play(); |
| | 40 | |
|
| 0 | 41 | | if (startTime > 0) { videoPlayers[id].SetSeekTime(startTime); } |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public void Pause(string id) |
| | 45 | | { |
| 0 | 46 | | videoPlayers[id].Pause(); |
| 0 | 47 | | } |
| | 48 | |
|
| | 49 | | public void SetVolume(string id, float volume) |
| | 50 | | { |
| 0 | 51 | | videoPlayers[id].SetVolume(volume); |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | public int GetHeight(string id) |
| | 55 | | { |
| 0 | 56 | | return videoPlayers[id].GetVideoHeight(); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public int GetWidth(string id) |
| | 60 | | { |
| 0 | 61 | | return videoPlayers[id].GetVideoWidth(); |
| | 62 | | } |
| | 63 | |
|
| | 64 | | public float GetTime(string id) |
| | 65 | | { |
| 0 | 66 | | return videoPlayers[id].GetPlaybackPosition(); |
| | 67 | | } |
| | 68 | |
|
| | 69 | | public float GetDuration(string id) |
| | 70 | | { |
| 0 | 71 | | return videoPlayers[id].GetDuration(); |
| | 72 | | } |
| | 73 | |
|
| | 74 | | public VideoState GetState(string id) |
| | 75 | | { |
| 0 | 76 | | DCLVideoPlayer videoPlayer = videoPlayers[id]; |
| | 77 | |
|
| 0 | 78 | | switch (videoPlayer.GetState()) |
| | 79 | | { |
| | 80 | | case DCLVideoPlayer.VideoPlayerState.Loading: |
| 0 | 81 | | return VideoState.LOADING; |
| | 82 | | case DCLVideoPlayer.VideoPlayerState.Error: |
| 0 | 83 | | return VideoState.ERROR; |
| | 84 | | case DCLVideoPlayer.VideoPlayerState.Ready: |
| 0 | 85 | | if (videoPlayer.GetTexture() == null) { return VideoState.READY; } |
| | 86 | |
|
| | 87 | | break; |
| | 88 | | } |
| | 89 | |
|
| 0 | 90 | | if (videoPlayer.IsBuffering()) { return VideoState.BUFFERING; } |
| | 91 | |
|
| 0 | 92 | | return videoPlayer.IsPlaying() ? VideoState.PLAYING : VideoState.PAUSED; |
| | 93 | | } |
| | 94 | |
|
| | 95 | | public string GetError(string id) |
| | 96 | | { |
| 0 | 97 | | return ""; |
| | 98 | | } |
| | 99 | |
|
| | 100 | | public void SetTime(string id, float second) |
| | 101 | | { |
| 0 | 102 | | videoPlayers[id].SetSeekTime(second); |
| 0 | 103 | | } |
| | 104 | |
|
| | 105 | | public void SetPlaybackRate(string id, float playbackRate) |
| | 106 | | { |
| 0 | 107 | | videoPlayers[id].SetPlaybackRate(playbackRate); |
| 0 | 108 | | } |
| | 109 | |
|
| | 110 | | public void SetLoop(string id, bool loop) |
| | 111 | | { |
| 0 | 112 | | videoPlayers[id].SetLoop(loop); |
| 0 | 113 | | } |
| | 114 | | } |