Example #1
0
        /// <summary>
        /// Performs the actions that this command implements.
        /// </summary>
        internal override void Execute()
        {
            var m = Manager.MediaElement;

            m.Clock.Reset();
            var seek = new SeekCommand(this.Manager, TimeSpan.Zero);

            seek.Execute();

            foreach (var renderer in m.Renderers.Values)
            {
                renderer.Stop();
            }

            m.MediaState = System.Windows.Controls.MediaState.Stop;
        }
        /// <summary>
        /// Performs the actions represented by this deferred task.
        /// </summary>
        protected override void PerformActions()
        {
            var m = MediaCore;

            m.Clock.Reset();
            m.State.UpdateMediaState(PlaybackStatus.Manual);
            var seek = new SeekCommand(m, TimeSpan.Zero);

            seek.Execute();
            m.State.UpdateMediaState(PlaybackStatus.Stop, m.WallClock);

            foreach (var renderer in m.Renderers.Values)
            {
                renderer.Stop();
            }
        }
Example #3
0
        /// <summary>
        /// Performs the actions represented by this deferred task.
        /// </summary>
        protected override void PerformActions()
        {
            var m = MediaCore;

            m.Log(MediaLogMessageType.Debug, $"Command {CommandType}: Entered");

            try
            {
                m.State.UpdateMediaState(PlaybackStatus.Manual);

                // Signal the start of a sync-buffering scenario
                m.Clock.Pause();

                // Wait for the cycles to complete
                var workerEvents = new IWaitEvent[] { m.BlockRenderingCycle, m.PacketReadingCycle };
                foreach (var workerEvent in workerEvents)
                {
                    workerEvent.Wait();
                }

                // Signal a change so the user get the chance to update
                // selected streams and options
                m.SendOnMediaChanging();

                // Side load subtitles
                m.PreloadSubtitles();

                // Capture the current media types before components change
                var oldMediaTypes = m.Container.Components.MediaTypes.ToArray();

                // Recreate selected streams as media components
                var mediaTypes = m.Container.UpdateComponents();
                m.State.UpdateFixedContainerProperties();

                // find all existing component blocks and renderers that no longer exist
                // We always remove the audio component in case there is a change in audio device
                var removableMediaTypes = oldMediaTypes
                                          .Where(t => mediaTypes.Contains(t) == false)
                                          .Union(new[] { MediaType.Audio })
                                          .Distinct()
                                          .ToArray();

                // find all existing component blocks and renderers that no longer exist
                foreach (var t in removableMediaTypes)
                {
                    // Remove the renderer for the component
                    if (m.Renderers.ContainsKey(t))
                    {
                        m.Renderers[t].Close();
                        m.Renderers.Remove(t);
                    }

                    // Remove the block buffer for the component
                    if (m.Blocks.ContainsKey(t))
                    {
                        m.Blocks[t]?.Dispose();
                        m.Blocks.Remove(t);
                    }
                }

                // Create the block buffers and renderers as necessary
                foreach (var t in mediaTypes)
                {
                    if (m.Blocks.ContainsKey(t) == false)
                    {
                        m.Blocks[t] = new MediaBlockBuffer(Constants.MaxBlocks[t], t);
                    }

                    if (m.Renderers.ContainsKey(t) == false)
                    {
                        m.Renderers[t] = MediaEngine.Platform.CreateRenderer(t, m);
                    }

                    m.Blocks[t].Clear();
                    m.Renderers[t].WaitForReadyState();
                }

                // Depending on whether or not the media is seekable
                // perform either a seek operation or a quick buffering operation.
                if (m.State.IsSeekable)
                {
                    // Let's simply do an automated seek
                    var seekCommand = new SeekCommand(m, m.WallClock);
                    seekCommand.Execute();
                    return;
                }
                else
                {
                    // Let's perform quick-buffering
                    m.Container.Components.RunQuickBuffering(m);

                    // Mark the renderers as invalidated
                    foreach (var t in mediaTypes)
                    {
                        m.InvalidateRenderer(t);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorException = ex;
            }
        }