/// <summary> /// Seeks to the specified target second. /// </summary> /// <param name="targetSecond">The target second.</param> public void Seek(decimal targetSecond) { if (IsLiveStream) { return; } if (AudioRenderer.HasInitialized) { AudioRenderer.Stop(); } MediaFramesExtractedDone.Wait(Constants.FrameExtractorWaitMs); RealtimeClock.Seek(targetSecond); this.m_Position = targetSecond; NotifyPlayStateChanged(); }
/// <summary> /// Rewinds and pauses media playback /// </summary> public void Stop() { if (IsLiveStream) { return; } if (AudioRenderer.HasInitialized) { AudioRenderer.Stop(); } MediaFramesExtractedDone.Wait(Constants.FrameExtractorWaitMs); this.HasMediaEnded = false; if (Position > StartTime) { RealtimeClock.Seek(StartTime); } }
/// <summary> /// Pauses media playback /// </summary> public void Pause() { if (IsLiveStream) { return; } if (IsPlaying == false) { return; } if (AudioRenderer.HasInitialized) { AudioRenderer.Stop(); } MediaFramesExtractedDone.Wait(Constants.FrameExtractorWaitMs); this.RealtimeClock.Pause(); }
/// <summary> /// Starts or resumes media playback /// </summary> public void Play() { if (AudioRenderer.HasInitialized) { AudioRenderer.Play(); } if (this.IsPlaying) { return; } if (this.HasMediaEnded) { return; } WaitForPlaybackReadyState(); this.RealtimeClock.Play(); }
/// <summary> /// Releases all managed and unmanaged resources /// </summary> public void Dispose() { if (IsCancellationPending) { return; } this.IsCancellationPending = true; this.VideoRenderTimer.Stop(); if (this.AudioRenderer != null) { if (this.AudioRenderer.HasInitialized) { this.AudioRenderer.Stop(); } this.AudioRenderer.Dispose(); this.AudioRenderer = null; } if (MediaFrameExtractorThread != null) { MediaFrameExtractorThread.Join(); MediaFrameExtractorThread = null; } if (MediaFramesExtractedDone != null) { try { MediaFramesExtractedDone.Dispose(); MediaFramesExtractedDone = null; } finally { } } if (LeadingFramesCache != null) { LeadingFramesCache.Clear(); LeadingFramesCache = null; } if (LaggingFramesCache != null) { LaggingFramesCache.Clear(); LaggingFramesCache = null; } if (VideoCodecContext != null) { fixed(AVCodecContext **videoCodecContextRef = &VideoCodecContext) { ffmpeg.avcodec_close(VideoCodecContext); ffmpeg.avcodec_free_context(videoCodecContextRef); VideoCodecContext = null; } } if (AudioCodecContext != null) { fixed(AVCodecContext **audioCodecContextRef = &AudioCodecContext) { ffmpeg.avcodec_close(AudioCodecContext); ffmpeg.avcodec_free_context(audioCodecContextRef); AudioCodecContext = null; } } if (VideoResampler != null) { ffmpeg.sws_freeContext(VideoResampler); VideoResampler = null; } if (AudioResampler != null) { fixed(SwrContext **audioResamplerRef = &AudioResampler) { ffmpeg.swr_close(AudioResampler); ffmpeg.swr_free(audioResamplerRef); AudioResampler = null; } } if (InputFormatContext != null) { fixed(AVFormatContext **inputFormatContextRef = &InputFormatContext) { ffmpeg.avformat_close_input(inputFormatContextRef); ffmpeg.avformat_free_context(InputFormatContext); InputFormatContext = null; } } if (DecodedPictureHolder != null) { ffmpeg.av_free(DecodedPictureHolder); DecodedPictureHolder = null; } if (DecodedWaveHolder != null) { ffmpeg.av_free(DecodedWaveHolder); DecodedWaveHolder = null; } }
/// <summary> /// Releases all managed and unmanaged resources /// </summary> public void Dispose() { if (IsCancellationPending) return; this.IsCancellationPending = true; this.VideoRenderTimer.Stop(); if (this.AudioRenderer != null) { if (this.AudioRenderer.HasInitialized) this.AudioRenderer.Stop(); this.AudioRenderer.Dispose(); this.AudioRenderer = null; } if (MediaFrameExtractorThread != null) { MediaFrameExtractorThread.Join(); MediaFrameExtractorThread = null; } if (MediaFramesExtractedDone != null) { try { MediaFramesExtractedDone.Dispose(); MediaFramesExtractedDone = null; } finally { } } if (PrimaryFramesCache != null) { PrimaryFramesCache.Clear(); PrimaryFramesCache = null; } if (SecondaryFramesCache != null) { SecondaryFramesCache.Clear(); SecondaryFramesCache = null; } if (VideoCodecContext != null) { fixed (AVCodecContext** videoCodecContextRef = &VideoCodecContext) { ffmpeg.avcodec_close(VideoCodecContext); ffmpeg.avcodec_free_context(videoCodecContextRef); VideoCodecContext = null; } } if (AudioCodecContext != null) { fixed (AVCodecContext** audioCodecContextRef = &AudioCodecContext) { ffmpeg.avcodec_close(AudioCodecContext); ffmpeg.avcodec_free_context(audioCodecContextRef); AudioCodecContext = null; } } if (VideoResampler != null) { ffmpeg.sws_freeContext(VideoResampler); VideoResampler = null; } if (AudioResampler != null) { fixed (SwrContext** audioResamplerRef = &AudioResampler) { ffmpeg.swr_close(AudioResampler); ffmpeg.swr_free(audioResamplerRef); AudioResampler = null; } } if (InputFormatContext != null) { fixed (AVFormatContext** inputFormatContextRef = &InputFormatContext) { ffmpeg.avformat_close_input(inputFormatContextRef); ffmpeg.avformat_free_context(InputFormatContext); InputFormatContext = null; } } if (DecodedPictureHolder != null) { ffmpeg.av_free(DecodedPictureHolder); DecodedPictureHolder = null; } if (DecodedWaveHolder != null) { ffmpeg.av_free(DecodedWaveHolder); DecodedWaveHolder = null; } }