public void Close(bool freePlayer, bool freeAudio, bool freeRenderTexture) { mVideoPlayer.Stop(); mAudioSource.Stop(); if (freePlayer) { GameObject.Destroy(mVideoPlayer); mVideoPlayer = null; } if (freeAudio) { GameObject.Destroy(mAudioSource); mAudioSource = null; } if (freeRenderTexture) { GameObject.Destroy(mRenderTexture); mRenderTexture = null; } mVideoHolder = null; mPromoData = null; mEndCallback = null; }
public VideoHandler(RawImage videoHolder, PromoData promoData, System.Action endCallback, RenderTexture renderTexture = null) { mVideoHolder = videoHolder; mPromoData = promoData; mRenderTexture = renderTexture; mEndCallback = endCallback; mVideoPlayer = mVideoHolder.gameObject.GetComponent <UnityEngine.Video.VideoPlayer>(); if (mVideoPlayer == null) { mVideoPlayer = mVideoHolder.gameObject.AddComponent <UnityEngine.Video.VideoPlayer>(); } mVideoPlayer.loopPointReached += OnLoopPointReached; mAudioSource = mVideoHolder.gameObject.GetComponent <AudioSource>(); if (mAudioSource == null) { mAudioSource = mVideoHolder.gameObject.AddComponent <AudioSource>(); } mVideoPlayer.source = UnityEngine.Video.VideoSource.Url; mVideoPlayer.url = mPromoData.VideoFileDownloaded; mVideoPlayer.audioOutputMode = UnityEngine.Video.VideoAudioOutputMode.AudioSource; mVideoPlayer.EnableAudioTrack(0, true); mVideoPlayer.SetTargetAudioSource(0, mAudioSource); mVideoPlayer.Prepare(); if (mRenderTexture == null) { mRenderTexture = new RenderTexture(int.Parse(mPromoData.width), int.Parse(mPromoData.height), 16, RenderTextureFormat.ARGB32); } mVideoPlayer.targetTexture = mRenderTexture; mVideoHolder.texture = mRenderTexture; }
public virtual bool OnReceivePromoData(string json) { PromoData newData = JsonUtility.FromJson <PromoData>(json); if (Data == newData) { return(false); } Data = newData; if (mDownloadThread != null) { StopCoroutine(mDownloadThread); } mDownloadThread = CRDownload(); StartCoroutine(mDownloadThread); if (EventOnDataChanged != null) { EventOnDataChanged(); } return(true); }