Esempio n. 1
0
        private void PlayNextSplashScreen()
        {
            if (_currentSplashScreen >= _splashScreens.Length)
            {
                SceneManager.LoadScene(_mainSceneName);
                return;
            }

            VideoPlayer.EventHandler eventHandler = null;
            eventHandler = vp => {
                _videoPlayer.loopPointReached -= eventHandler;

                _currentSplashScreen++;
                PlayNextSplashScreen();
            };

            SplashScreenConfig config = _splashScreens[_currentSplashScreen];

            _videoPlayer.clip = config.videoClip;

            // config the volume for each track
            _videoPlayer.SetDirectAudioVolume(0, 1.0f);
            for (ushort i = 0; i < config.volume.Length; ++i)
            {
                _videoPlayer.SetDirectAudioVolume(i, config.volume[i]);
            }

            _videoPlayer.loopPointReached += eventHandler;
            _videoPlayer.Play();
        }
Esempio n. 2
0
    /// <summary>
    /// Starts the play.
    /// </summary>
    /// <param name="filePath">File path.</param>
    public void StartPlay(string filePath, VideoPlayer.EventHandler callBack)
    {
        Log.debug(this, "StartPlay==========filePath:" + filePath);
        if (vPlayer.isPlaying)
        {
            vPlayer.Stop();
        }
        //vPlayer.url = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
        //vPlayer.url = "file:///C:/Unity3d/dangmu/dangmu/Assets/Dangmu/Textures/WeChat_20180305193437.mp4";
        //vPlayer.URL = "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4";
        vPlayer.url = filePath;


        //当VideoPlayer全部设置好的时候调用
        if (null == callBack)
        {
            vPlayer.prepareCompleted += Prepared;
        }
        else
        {
            vPlayer.prepareCompleted += callBack;
        }

        //启动播放器
        vPlayer.Prepare();
        Init();
        vPlayer.Play();
    }
        void Start()
        {
            _isDirtyStreams = true;

            internetTimeReady       = false;
            internetTimerIsActive   = false;
            scheduledStreamIsActive = false;

            StreamState = ExpoScheduledStreamState.Start;

            StreamRoomName = ExpoScheduledStreamData.RoomName;

            if (autoStart)
            {
                StartInternetTimer();
                StartScheduledStream();
            }

            if (mPlayer != null)
            {
                // AVPro player
                //mPlayer.Events.AddListener(OnVideoEvent);

                // YouTubePlayer
                prepareHandler = (source) => { OnReadyToStart(); };
                mPlayer.videoPlayer.prepareCompleted += prepareHandler;

                mPlayer.OnVideoFinished.AddListener(OnFinished);
            }
        }
Esempio n. 4
0
 private void ClearCallback()
 {
     if (m_Callback != null)
     {
         m_Player.loopPointReached -= m_Callback;
     }
     m_Callback = null;
 }
Esempio n. 5
0
    void Start()
    {
        vp = this.GetComponent <VideoPlayer>();                            //获取视频播放器组件

        VideoPlayer.EventHandler e = new VideoPlayer.EventHandler(Finish); //建立一个事件触发委托

        vp.loopPointReached += e;                                          //把这个委托添加到一遍循环结束后(到达了循环点)事件触发就触发这个我们的委托
    }
Esempio n. 6
0
 private void OnDestroy()
 {
     m_VideoPlayer.prepareCompleted -= OpenVideoCompleted;
     m_VideoPlayer.loopPointReached -= PlayVideoCompleted;
     m_RenderTexture     = null;
     m_VideoPlayer       = null;
     VideoOpenHandler    = null;
     VideoPlayEndHandler = null;
 }
    /// <summary>
    /// 注册视频播放目标帧数回调
    /// </summary>
    /// <param name="time">目标帧数</param>
    /// <param name="eventHandler">回调</param>
    public void RegisterEvent(long targetFrame, VideoPlayer.EventHandler eventHandler)
    {
        List <VideoPlayer.EventHandler> list = null;

        if (!_videoPlayerEventHandlers.TryGetValue(targetFrame, out list))
        {
            list = new List <VideoPlayer.EventHandler>();
        }
        list.Add(eventHandler);
        _videoPlayerEventHandlers[targetFrame] = list;
    }
Esempio n. 8
0
 public void SetPrepareCompleted(Action callback)
 {
     if (callback != null)
     {
         onPrepareCompleted = (video) =>
         {
             callback();
         };
         _videoPlayer.prepareCompleted += onPrepareCompleted;
     }
 }
    /// <summary>
    /// 注册视频播放目标时间回调
    /// </summary>
    /// <param name="time">目标时间</param>
    /// <param name="eventHandler">回调</param>
    public void RegisterEvent(float time, VideoPlayer.EventHandler eventHandler)
    {
        if (eventHandler == null)
        {
            return;
        }
        long targetFrame = (long)(time * m_videoClip.frameRate);

        RegisterEvent(targetFrame, eventHandler);
        Debug.LogFormat("already RegisterEvent:time:{0},target frame:{1}", time, targetFrame);
    }
Esempio n. 10
0
    void OnDestroy()
    {
        if (onPrepareCompleted != null)
        {
            _videoPlayer.prepareCompleted -= onPrepareCompleted;
            onPrepareCompleted             = null;
        }

        _videoPlayer.Stop();

        // 清理掉创建rt
        Destroy(_renderTexture);
    }
Esempio n. 11
0
 void        OnFinish(VideoPlayer videoPlayer)
 {
     if (m_OnFinish != null)
     {
         m_OnFinish(videoPlayer);
         m_OnFinish = null;
     }
     if (m_VideoPlayer != null)
     {
         m_VideoPlayer.gameObject.SetActive(false);
     }
     GTWindowManager.Instance.LockNGUI(false);
 }
Esempio n. 12
0
 public void Stop()
 {
     if (m_VideoPlayer != null)
     {
         m_VideoPlayer.Stop();
         m_VideoPlayer.gameObject.SetActive(false);
     }
     if (m_OnCancel != null)
     {
         m_OnCancel.Invoke(m_VideoPlayer);
         m_OnCancel = null;
     }
     GTWindowManager.Instance.LockNGUI(false);
 }
        private void Awake()
        {
            PrepareCompleteEvent         += (vp) => { };
            videoPlayer                   = gameObject.GetComponent <VideoPlayer>();
            videoPlayer.prepareCompleted += (vp) => PrepareCompleteEvent.Invoke(vp);
            videoPlayer.prepareCompleted += (vp) =>
            {
                if (readyToPlay)
                {
                    Play();
                }
                readyToPlay = false;
            };

            _texture = new Texture2D(0, 0);
        }
Esempio n. 14
0
    public void PlayVideo(VideoClip clip, VideoPlayer.EventHandler callback)
    {
        m_Callback = callback;
        m_Camera.SetActive(true);
        m_Player.clip = clip;
        if (callback != null)
        {
            m_Player.loopPointReached += callback;
        }

        // Start playback. This means the VideoPlayer may have to prepare (reserve
        // resources, pre-load a few frames, etc.). To better control the delays
        // associated with this preparation one can use videoPlayer.Prepare() along with
        // its prepareCompleted event.
        m_Player.Play();
        //LogManager.Log(" Play >> " , Time.realtimeSinceStartup);
    }
Esempio n. 15
0
    void LoadVideo(string url, bool isLooping, bool cache, VideoPlayer.EventHandler cb)
    {
        var prevPlayer = curPlayer;

        if (!cache)
        {
            curPlayer = noCachePlayer;
            if (!curPlayer.url.Equals(url))
            {
                curPlayer.url = url;
            }
        }
        else if (playerCache.ContainsKey(url))
        {
            curPlayer = playerCache[url];
            curPlayer.targetTexture = videoTex;
        }
        else
        {
            curPlayer = CacheVideoPlayer(url);
            curPlayer.targetTexture = videoTex;
        }

        if (prevPlayer != null && prevPlayer.isPlaying)
        {
            prevPlayer.Pause();
            prevPlayer.frame = 0;
        }

        curPlayer.isLooping = isLooping;
        if (!curPlayer.isPrepared)
        {
            if (cb != null)
            {
                curPlayer.prepareCompleted += cb;
            }
            curPlayer.Prepare();
        }
        else if (cb != null)
        {
            cb(curPlayer);
        }
    }
Esempio n. 16
0
        private void PlayNextSplashScreen()
        {
            if (_currentSplashScreen >= _splashScreens.Length)
            {
                SceneManager.LoadScene(_mainSceneName);
                return;
            }

            VideoPlayer.EventHandler eventHandler = null;
            eventHandler = vp => {
                _videoPlayer.loopPointReached -= eventHandler;

                _currentSplashScreen++;
                PlayNextSplashScreen();
            };

            _videoPlayer.clip              = _splashScreens[_currentSplashScreen];
            _videoPlayer.loopPointReached += eventHandler;
            _videoPlayer.Play();
        }
Esempio n. 17
0
        public void Trigger(int id, VideoPlayer.EventHandler onCancel = null, VideoPlayer.EventHandler onFinish = null)
        {
            DVideo db = ReadCfgVideo.GetDataById(id);

            if (db == null)
            {
                return;
            }
            if (m_VideoPlayer == null)
            {
                m_VideoPlayer = CreateVideoPlayer();
            }
            VideoClip clip = GTResourceManager.Instance.Load <VideoClip>(db.Path);

            m_OnCancel                      = onCancel;
            m_OnFinish                      = onFinish;
            m_VideoPlayer.clip              = clip;
            m_VideoPlayer.loopPointReached += OnFinish;
            m_VideoPlayer.Play();
            GTWindowManager.Instance.LockNGUI(true);
        }
Esempio n. 18
0
 public void Play(VideoPlayer.EventHandler callback)
 {
     videoPlayerObj.SetActive(true);
     videoPlayer.Play();
     videoPlayer.loopPointReached += callback;
 }
Esempio n. 19
0
    // Update is called once per frame
    void Update()
    {
        if (done == false && (command.type == FMVManager.CommandType.AUDIO || command.type == FMVManager.CommandType.SONG))
        {
            AudioSource audioSource = gameObject.GetComponent <AudioSource>();
            if (audioSource && audioSource.clip)
            {
                if (audioSource.clip.loadState == AudioDataLoadState.Loaded || audioSource.clip.loadState == AudioDataLoadState.Failed)
                {
                    if (audioSource.isPlaying == false)
                    {
                        Debug.Log("detected song end " + command.file);
                        EndReached(vp);
                        prepared = true;
                    }
                }
            }
        }
        if (prepared == false)
        {
            return;
        }

        if (rp != null)
        {
            if (rp.transform.position.z > 9001)
            {
                rp.transform.position = new Vector3(0, 0, rp.transform.position.z - Time.deltaTime);
            }
            else if (rp.transform.position.z > 9000 && freezeFrame == false)
            {
                var r = rp.GetComponent <MeshRenderer>();
                var m = r.material;
                //m.mainTexture = Instantiate(m.mainTexture);
                m.SetColor("_keyingColor", transparentColor);
                m.SetFloat("_thresh", threshold);
                m.SetFloat("_slope", slope);
                rp.transform.position = new Vector3(0, 0, command.z);
            }
            float scale = Camera.main.aspect / 2.0f;
            if (scale > 1.0f)
            {
                scale = 1.0f;
            }
            rp.transform.localScale = new Vector3(scale * 2.0f, 1, scale);

            if (done && vp != null)
            {
                var r  = rp.GetComponent <MeshRenderer>();
                var m  = r.material;
                var rt = m.mainTexture as RenderTexture;

                RenderTexture currentActiveRT = RenderTexture.active;
                RenderTexture.active = rt;

                Texture2D tex = new Texture2D(rt.width, rt.height);
                tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0, false);
                tex.Apply();

                RenderTexture.active = currentActiveRT;
                Destroy(m.mainTexture);

                m.mainTexture = tex;
                Destroy(vp);
                Destroy(this.GetComponent <AudioSource>());
                vp = null;

                m.SetColor("_keyingColor", transparentColor);
                m.SetFloat("_thresh", threshold);
                m.SetFloat("_slope", slope);
                rp.transform.position = new Vector3(0, 0, command.z);
            }
        }

        if (fadeInTime > 0)
        {
            vp.targetCameraAlpha += fadeInSpeed * Time.deltaTime;
            fadeInTime           -= Time.deltaTime;

            if (fadeInTime <= 0)
            {
                vp.targetCameraAlpha = 1;
                if (freezeFrame == false)
                {
                    vp.Play();
                }
                else
                {
                    EndReached(vp);
                }
            }
        }
        else if (fadingOut)
        {
            if (fadeOutTime > 0)
            {
                vp.targetCameraAlpha -= fadeOutSpeed * Time.deltaTime;
                fadeOutTime          -= Time.deltaTime;
            }
            else if (fadeOutSpeed > 0)
            {
                vp.targetCameraAlpha = 0;
                done = true;
                if (fadeOutFinished != null)
                {
                    fadeOutFinished.Invoke(vp);
                    fadeOutFinished = null;
                }
                Destroy(this.gameObject, 15);
            }
            else if (done == false)
            {
                done = true;
                if (fadeOutFinished != null)
                {
                    fadeOutFinished.Invoke(vp);
                    fadeOutFinished = null;
                }
                //Destroy(this.gameObject);//only destroy when there is a video to replace it?
            }
        }

        /*else if (vp.targetCameraAlpha != 1)
         * {
         *  vp.targetCameraAlpha = 1;
         *  vp.Play();
         * }*/
    }