示例#1
0
 /// <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;
     });
 }
示例#2
0
        /// <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;
            }
        }
示例#3
0
        /// <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;
                });
            }
        }
示例#4
0
        /// <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);
            });
        }