protected override void OnStartRunning() { base.OnStartRunning(); if (initialized) { return; } VideoHTMLNativeCalls.js_initialize(); initialized = true; }
public LoadResult CheckLoading(IntPtr cppwrapper, EntityManager em, Entity e, ref VideoClip vp, ref VideoClipLoadingState vps, ref VideoClipLoadFromFile clip, ref VideoClipLoading unused) { int res = VideoHTMLNativeCalls.js_check_loading(vps.index); if (res == 0) // Error loading { return(LoadResult.failed); } else if (res == 2) { var src = em.GetBufferAsString <VideoClipLoadFromFileName>(e); var s = "Loaded video: "; s += src; Debug.Log(s); return(LoadResult.success); } return(LoadResult.stillWorking); //1 or -1 }
public void StartLoad(EntityManager em, Entity e, ref VideoClip vp, ref VideoClipLoadingState ps, ref VideoClipLoadFromFile clip, ref VideoClipLoading unused) { if (em.HasComponent <VideoClipHTML>(e)) { if (em.HasComponent <VideoClipLoadFromFileName>(e)) { var src = em.GetBufferAsString <VideoClipLoadFromFileName>(e); var clipHTML = em.GetComponentData <VideoClipHTML>(e); int index = VideoHTMLNativeCalls.js_create_video_element(src, clipHTML.controls, clipHTML.loop, (int)clipHTML.region.x, (int)clipHTML.region.y, (int)clipHTML.region.width, (int)clipHTML.region.height); clipHTML.index = index; ps.index = index; } else { var s = "Missing VideoClipLoadFromFileName component on entity "; s += e.ToString(); Debug.Log(s); } } }
protected override void OnUpdate() { EntityManager em = EntityManager; EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp); //Init: Add VideoClipHTML private comp to a clip added to the player Entities.ForEach((Entity e, ref VideoPlayer vp) => { if (em.Exists(vp.clip)) { if (!em.HasComponent <VideoClipHTML>(vp.clip)) { float2 videoSize; int left, top, width, height; if (em.HasComponent <RectTransform>(e)) { float3 worldPos = TransformHelpers.ComputeWorldPosition(this, e); videoSize = UILayoutService.GetRectTransformSizeOfEntity(this, e); left = (int)(worldPos.x - (videoSize.x / 2.0f)); top = (int)(worldPos.y - (videoSize.y / 2.0f)); } else { //Without rectT the size of the video will be the screen size; videoSize = UILayoutService.GetScreenSize(this); left = 0; top = 0; } width = (int)videoSize.x; height = (int)videoSize.y; ecb.AddComponent(vp.clip, new VideoClipHTML() { loop = vp.loop, controls = vp.controls, region = new Rect(left, top, width, height) }); //Now that we have all info for the loading, restart loading if (em.HasComponent <VideoClipLoading>(vp.clip)) { ecb.RemoveComponent <VideoClipLoading>(vp.clip); } } } }); ecb.Playback(em); ecb.Dispose(); ecb = new EntityCommandBuffer(Allocator.Temp); //Once the video is loaded (VideoClip has been removed), get the current time or remove the video if VideoPlayerAutoDeleteOnEnd has been attached Entities.WithAll <VideoPlayer>().ForEach((Entity e) => { var vp = em.GetComponentData <VideoPlayer>(e); if (em.Exists(vp.clip) && em.HasComponent <VideoClipHTML>(vp.clip)) { var clipHtml = em.GetComponentData <VideoClipHTML>(vp.clip); int playingStatus = VideoHTMLNativeCalls.js_check_isPlaying(clipHtml.index); if (em.HasComponent <VideoPlayerAutoDeleteOnEnd>(e) && playingStatus == 2 && !vp.loop) { ecb.DestroyEntity(vp.clip); } else if (playingStatus == 1) { vp.currentTime = VideoHTMLNativeCalls.js_getCurrentTime(clipHtml.index); } } }); ecb.Playback(em); ecb.Dispose(); ecb = new EntityCommandBuffer(Allocator.Temp); //Remove Video HTML element Entities.WithNone <VideoClip>().ForEach( (Entity e, ref VideoClipHTML v) => { VideoHTMLNativeCalls.js_remove_video_element(v.index); }); ecb.Playback(em); ecb.Dispose(); //Remove VideoClipHTML priv compo on clip entities ecb = new EntityCommandBuffer(Allocator.Temp); Entities.WithAll <VideoClipHTML>().WithNone <VideoClip>().ForEach(e => { ecb.RemoveComponent <VideoClipHTML>(e); }); ecb.Playback(em); ecb.Dispose(); }