Beispiel #1
0
        private bool CanFireEvent(MediaPlayerEvent.EventType et, bool hasFired)
        {
            bool result = false;

            if (m_events != null && m_Control != null && !hasFired)
            {
                switch (et)
                {
                case MediaPlayerEvent.EventType.FinishedPlaying:
                    result = (!m_Control.IsLooping() && m_Control.CanPlay() && m_Control.IsFinished());
                    break;

                case MediaPlayerEvent.EventType.MetaDataReady:
                    result = (m_Control.HasMetaData());
                    break;

                case MediaPlayerEvent.EventType.FirstFrameReady:
                    result = (m_Texture != null && m_Control.CanPlay() && m_Texture.GetTextureFrameCount() > 0);
                    break;

                case MediaPlayerEvent.EventType.ReadyToPlay:
                    result = (!m_Control.IsPlaying() && m_Control.CanPlay());
                    break;

                case MediaPlayerEvent.EventType.Started:
                    result = (m_Control.IsPlaying());
                    break;
                }
            }
            return(result);
        }
Beispiel #2
0
        private void UpdateEvents()
        {
            if (m_events != null && m_Control != null)
            {
                // Finished event
                if (!m_EventFired_FinishedPlaying && !m_Control.IsLooping() && m_Control.CanPlay() && m_Control.IsFinished())
                {
                    m_EventFired_FinishedPlaying = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.FinishedPlaying, ErrorCode.None);
                }

                // Keep track of whether the Playing state has changed
                if (m_EventFired_Started && !m_Control.IsPlaying())
                {
                    // Playing has stopped
                    m_EventFired_Started = false;
                }

                if (m_EventFired_FinishedPlaying && m_Control.IsPlaying() && !m_Control.IsFinished())
                {
                    m_EventFired_FinishedPlaying = false;
                }

                // Fire events
                if (!m_EventFired_MetaDataReady && m_Control.HasMetaData())
                {
                    m_EventFired_MetaDataReady = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.MetaDataReady, ErrorCode.None);
                }
                if (!m_EventFired_ReadyToPlay && !m_Control.IsPlaying() && m_Control.CanPlay())
                {
                    m_EventFired_ReadyToPlay = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.ReadyToPlay, ErrorCode.None);
                }
                if (!m_EventFired_Started && m_Control.IsPlaying())
                {
                    m_EventFired_Started = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.Started, ErrorCode.None);
                }
                if (m_Texture != null)
                {
                    if (!m_EventFired_FirstFrameReady && m_Control.CanPlay() && m_Texture.GetTextureFrameCount() > 0)
                    {
                        m_EventFired_FirstFrameReady = true;
                        m_events.Invoke(this, MediaPlayerEvent.EventType.FirstFrameReady, ErrorCode.None);
                    }
                }
            }
        }
        private void UpdateEvents()
        {
            // TODO: investigate weird bug where instantiated MediaPlayer's have m_events set to NULL..
            if (m_events != null && m_Control != null)
            {
                // Keep track of whether the Playing state has changed
                if (m_EventFired_Started && !m_Control.IsPlaying())
                {
                    // Playing has stopped
                    m_EventFired_Started = false;
                }

                if (m_EventFired_FinishedPlaying && m_Control.IsPlaying() && !m_Control.IsFinished())
                {
                    m_EventFired_FinishedPlaying = false;
                }

                // Fire events
                if (!m_EventFired_MetaDataReady && m_Control.HasMetaData())
                {
                    m_EventFired_MetaDataReady = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.MetaDataReady);
                }
                if (!m_EventFired_ReadyToPlay && !m_Control.IsPlaying() && m_Control.CanPlay())
                {
                    m_EventFired_ReadyToPlay = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.ReadyToPlay);
                }
                if (!m_EventFired_Started && m_Control.IsPlaying())
                {
                    m_EventFired_Started = true;
                    m_events.Invoke(this, MediaPlayerEvent.EventType.Started);
                }
                if (m_Texture != null)
                {
                    if (!m_EventFired_FirstFrameReady && m_Control.CanPlay() && m_Texture.GetTextureFrameCount() > 0)
                    {
                        m_EventFired_FirstFrameReady = true;
                        m_events.Invoke(this, MediaPlayerEvent.EventType.FirstFrameReady);
                    }
                }
            }
        }
Beispiel #4
0
		private void UpdateTimeScale()
		{
			if (Time.timeScale != 1f || Time.captureFramerate != 0)
			{
				if (m_Control.IsPlaying())
				{
					m_Control.Pause();
					_timeScaleIsControlling = true;
					_timeScaleVideoTime = m_Control.GetCurrentTimeMs();
				}

				if (_timeScaleIsControlling)
				{
					// Progress time
					_timeScaleVideoTime += (Time.deltaTime * 1000f);

					// Handle looping
					if (m_Control.IsLooping() && _timeScaleVideoTime >= Info.GetDurationMs())
					{
						// TODO: really we should seek to (_timeScaleVideoTime % Info.GetDurationMs())
						_timeScaleVideoTime = 0f;
					}

					int preSeekFrameCount = m_Texture.GetTextureFrameCount();

					// Seek to the new time
					{
						float preSeekTime = Control.GetCurrentTimeMs();

						// Seek
						m_Control.Seek(_timeScaleVideoTime);

						// Early out, if after the seek the time hasn't changed, the seek was probably too small to go to the next frame.
						// TODO: This behaviour may be different on other platforms (not Windows) and needs more testing.
						if (Mathf.Approximately(preSeekTime, m_Control.GetCurrentTimeMs()))
						{
							return;
						}
					}

					// Wait for the new frame to arrive
					if (!m_Control.WaitForNextFrame(GetDummyCamera(), preSeekFrameCount))
					{
						// If WaitForNextFrame fails (e.g. in android single threaded), we run the below code to asynchronously wait for the frame
						System.DateTime startTime = System.DateTime.Now;
						int lastFrameCount = TextureProducer.GetTextureFrameCount();

						while (m_Control != null && (System.DateTime.Now - startTime).TotalMilliseconds < (double)TimeScaleTimeoutMs)
						{
							m_Player.Update();
							m_Player.Render();
							GetDummyCamera().Render();
							if (lastFrameCount != TextureProducer.GetTextureFrameCount())
							{
								break;
							}
						}
					}
				}
			}
			else
			{
				// Restore playback when timeScale becomes 1
				if (_timeScaleIsControlling)
				{
					m_Control.Play();
					_timeScaleIsControlling = false;
				}
			}
		}