| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Models; |
| | 6 | | using Decentraland.Sdk.Ecs6; |
| | 7 | |
|
| | 8 | | namespace DCL.Components |
| | 9 | | { |
| | 10 | | public class DCLVideoClip : BaseDisposable |
| | 11 | | { |
| 1 | 12 | | private static readonly string[] NO_STREAM_EXTENSIONS = { ".mp4", ".ogg", ".mov", ".webm" }; |
| | 13 | |
|
| | 14 | | [Serializable] |
| | 15 | | public class Model : BaseModel |
| | 16 | | { |
| | 17 | | public string url; |
| | 18 | |
|
| | 19 | | public override BaseModel GetDataFromJSON(string json) => |
| 17 | 20 | | Utils.SafeFromJson<Model>(json); |
| | 21 | |
|
| | 22 | | public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel) |
| | 23 | | { |
| 0 | 24 | | if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.VideoClip) |
| 0 | 25 | | return Utils.SafeUnimplemented<DCLVideoClip, Model>(expected: ComponentBodyPayload.PayloadOneofCase. |
| | 26 | |
|
| 0 | 27 | | var pb = new Model(); |
| 0 | 28 | | if (pbModel.VideoClip.HasUrl) pb.url = pbModel.VideoClip.Url; |
| | 29 | |
|
| 0 | 30 | | return pb; |
| | 31 | | } |
| | 32 | | } |
| | 33 | |
|
| 35 | 34 | | public bool isExternalURL { get; private set; } |
| 35 | 35 | | public bool isStream { get; private set; } |
| | 36 | |
|
| 17 | 37 | | public DCLVideoClip() |
| | 38 | | { |
| 17 | 39 | | model = new Model(); |
| 17 | 40 | | } |
| | 41 | |
|
| | 42 | | public override int GetClassId() => |
| 0 | 43 | | (int) CLASS_ID.VIDEO_CLIP; |
| | 44 | |
|
| | 45 | | public override IEnumerator ApplyChanges(BaseModel newModel) |
| | 46 | | { |
| 17 | 47 | | Model model = (Model) newModel; |
| 17 | 48 | | isExternalURL = model.url.StartsWith("http://") || model.url.StartsWith("https://"); |
| | 49 | |
|
| 17 | 50 | | string urlPath = model.url; |
| 17 | 51 | | if (Uri.TryCreate(urlPath, UriKind.Absolute, out Uri uri)) |
| | 52 | | { |
| 17 | 53 | | urlPath = uri.AbsolutePath; |
| | 54 | | } |
| 85 | 55 | | isStream = !NO_STREAM_EXTENSIONS.Any(x => urlPath.EndsWith(x)); |
| 17 | 56 | | yield break; |
| | 57 | | } |
| | 58 | |
|
| | 59 | | public string GetUrl() |
| | 60 | | { |
| 18 | 61 | | Model model = (Model) this.model; |
| | 62 | |
|
| 18 | 63 | | string contentsUrl = model.url; |
| | 64 | |
|
| 18 | 65 | | if (!isExternalURL) |
| | 66 | | { |
| 0 | 67 | | scene.contentProvider.TryGetContentsUrl(model.url, out contentsUrl); |
| | 68 | | } |
| | 69 | |
|
| 18 | 70 | | return contentsUrl; |
| | 71 | | } |
| | 72 | | } |
| | 73 | | } |