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