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(); }