private void CallbackReadyPlayer(string message) { // Texture settings IntPtr texPtr = AVPlayerConnect.AVPlayerGetTexturePtr(avPlayer); Texture2D texture = Texture2D.CreateExternalTexture( 512, 512, TextureFormat.BGRA32, false, false, texPtr); texture.UpdateExternalTexture(texPtr); videoSizeWidth = AVPlayerConnect.AVPlayerGetVideoWidth(avPlayer); videoSizeHeight = AVPlayerConnect.AVPlayerGetVideoHeight(avPlayer); if (videoObject != null) { Renderer renderer = videoObject.GetComponent <Renderer>(); if (renderer != null) { Material material = renderer.material; if (material != null) { Vector2 scale = new Vector2(1f, -1f); material.SetTextureScale("_MainTex", scale); material.SetTexture("_MainTex", texture); } } } // Render settings StartCoroutine(OnRender()); // Play settings AVPlayerConnect.AVPlayerSetLoop(avPlayer, true); AVPlayerConnect.AVPlayerPlay(avPlayer); // Callbacks var videoSizeEvent = new VideoSizeEvent(); videoSizeEvent.SetCallback(avPlayer, (sender, width, height) => { StartCoroutine(OnUpdateVideoSize(width, height)); }); }
private void CallbackReadyPlayer(string message) { videoDuration = AVPlayerConnect.AVPlayerGetDuration(avPlayer); // Texture settings IntPtr texPtr = AVPlayerConnect.AVPlayerGetTexturePtr(avPlayer); Texture2D texture = Texture2D.CreateExternalTexture( 512, 512, TextureFormat.BGRA32, false, false, texPtr); texture.UpdateExternalTexture(texPtr); videoSizeWidth = AVPlayerConnect.AVPlayerGetVideoWidth(avPlayer); videoSizeHeight = AVPlayerConnect.AVPlayerGetVideoHeight(avPlayer); if (videoImage != null) { videoImage.texture = texture; Vector2 scale = new Vector2(1f, -1f); videoImage.material.SetTextureScale("_MainTex", scale); } StartCoroutine(OnRender()); // Seek settings if (seekSlider != null) { seekSlider.interactable = true; seekSlider.maxValue = videoDuration; seekSlider.minValue = 0f; seekSlider.value = 0f; SliderEventTrigger trigger = seekSlider.GetComponentInChildren <SliderEventTrigger>(); if (trigger != null) { trigger.BeginAction = SeekSliderInitializePointerDrag; trigger.MovingAction = SeekSliderDrag; trigger.EndAction = SeekSliderPointerUp; } } StartCoroutine(OnUpdateText()); StartCoroutine(OnUpdateSeekSlider()); // Callback settings AVPlayerConnect.AVPlayerSetOnEndTime( avPlayer, transform.root.gameObject.name, ((Action <string>)CallbackEndTime).Method.Name); AVPlayerConnect.AVPlayerSetOnSeek( avPlayer, transform.root.gameObject.name, ((Action <string>)CallbackSeek).Method.Name); VideoSizeEvent videoSizeEvent = new VideoSizeEvent(); videoSizeEvent.SetCallback(avPlayer, (sender, width, height) => { StartCoroutine(OnUpdateVideoSize(width, height)); }); // UI settings if (prepareButton != null) { prepareButton.interactable = false; } if (playButton != null) { playButton.interactable = true; } }