/// <summary> /// Executed when the Close method is called on the parent MediaElement /// </summary> public void Close() { MediaElement.InvokeOnUI(() => { if (TargetBitmap == null) { return; } TargetBitmap = null; MediaElement.ViewBox.Source = TargetBitmap; }); }
/// <summary> /// Destroys the audio renderer. /// Makes it useless. /// </summary> private void Destroy() { try { // Remove the event handler if (Application.Current != null) { MediaElement.InvokeOnUI(() => { Application.Current.Exit -= OnApplicationExit; }); } } catch { } if (AudioDevice != null) { AudioDevice.Stop(); AudioDevice.Dispose(); AudioDevice = null; } if (AudioBuffer != null) { AudioBuffer.Dispose(); AudioBuffer = null; } }
/// <summary> /// Initializes a new instance of the <see cref="AudioRenderer"/> class. /// </summary> /// <param name="mediaElement">The media element.</param> public AudioRenderer(MediaElement mediaElement) { MediaElement = mediaElement; m_Format = new WaveFormat(AudioParams.Output.SampleRate, AudioParams.OutputBitsPerSample, AudioParams.Output.ChannelCount); if (WaveFormat.BitsPerSample != 16 || WaveFormat.Channels != 2) { throw new NotSupportedException("Wave Format has to be 16-bit and 2-channel."); } BytesPerSample = WaveFormat.BitsPerSample / 8; SilenceBuffer = new byte[m_Format.BitsPerSample / 8 * m_Format.Channels * 2]; if (MediaElement.HasAudio) { Initialize(); } if (Application.Current != null) { MediaElement.InvokeOnUI(() => { Application.Current.Exit += OnApplicationExit; }); } }
/// <summary> /// Renders the specified media block. /// </summary> /// <param name="mediaBlock">The media block.</param> /// <param name="clockPosition">The clock position.</param> /// <param name="renderIndex">Index of the render.</param> public void Render(MediaBlock mediaBlock, TimeSpan clockPosition, int renderIndex) { var block = mediaBlock as VideoBlock; if (block == null) { return; } MediaElement.InvokeOnUI(() => { var updateRect = new Int32Rect(0, 0, block.PixelWidth, block.PixelHeight); TargetBitmap.WritePixels(updateRect, block.Buffer, block.BufferLength, block.BufferStride); }); }