/// <summary>
        /// Unregisters the specified media plugin so that it is no longer managed by this heuristics plugin.
        /// </summary>
        /// <param name="mediaPlugin">The media plugin to unregister.</param>
        public void UnregisterPlugin(IMediaPlugin mediaPlugin)
        {
            var ssme = mediaPlugin.VisualElement as SmoothStreamingMediaElement;

            if (IsLoaded && ssme != null)
            {
                if (ssme == _syncManager.HeuristicMasterMedia)
                {
                    _syncManager.HeuristicManager.StopMonitoring();
                    _syncManager.HeuristicMasterMedia = null;
                }

                if (ssme == _syncManager.MainMedia)
                {
                    _syncManager.MainMedia = null;
                }

                SlaveMediaElement subMediaElement =
                    _syncManager.SubMediaElements.Where(i => i.MediaElement == ssme).FirstOrDefault();

                if (subMediaElement != null)
                {
                    _syncManager.SubMediaElements.Remove(subMediaElement);
                    _syncManager.ResetHeuristics();
                }
            }
        }
        /// <summary>
        /// Registers the specified media plugin so that it can be managed by this heuristics plugin.
        /// </summary>
        /// <param name="mediaPlugin">The media plugin to register.</param>
        /// <param name="priority">The relative priority of this media plugin</param>
        /// <param name="enableSync">Indicates if synchronization of this media plugin with others should be enabled.</param>
        public void RegisterPlugin(IMediaPlugin mediaPlugin, int priority, bool enableSync)
        {
            var ssme = mediaPlugin.VisualElement as SmoothStreamingMediaElement;

            if (IsLoaded && ssme != null)
            {
                if (priority == 0)
                {
                    _syncManager.HeuristicMasterMedia = ssme;
                    _syncManager.RegisterMaster(ssme, ssme.Position);
                    _syncManager.ResetHeuristics();
                }
                else
                {
                    var slave = new SlaveMediaElement
                    {
                        IsLogicalSyncEnabled = enableSync,
                        MediaElement         = ssme,
                        Tolerance            = TimeSpan.FromMilliseconds(_settings.SyncToleranceMillis)
                    };

                    _syncManager.SubMediaElements.Add(slave);
                    if (_syncManager.HeuristicMasterMedia != null)
                    {
                        _syncManager.ResetHeuristics();
                    }
                }
            }
        }
        private void CleanUp()
        {
            SlaveMediaElement mainMedia =
                (from Media in SubMediaElements where Media.MediaElement == MainMedia select Media).SingleOrDefault();

            if (mainMedia != null)
            {
                SubMediaElements.Remove(mainMedia);
            }
        }
        /// <summary>
        /// Registers the specified media plugin so that it can be managed by this heuristics plugin.
        /// </summary>
        /// <param name="mediaPlugin">The media plugin to register.</param>
        /// <param name="priority">The relative priority of this media plugin</param>
        /// <param name="enableSync">Indicates if synchronization of this media plugin with others should be enabled.</param>
        public void RegisterPlugin(IMediaPlugin mediaPlugin, int priority, bool enableSync)
        {
            var ssme = mediaPlugin.VisualElement as SmoothStreamingMediaElement;

            if (IsLoaded && ssme != null)
            {
                if (priority == 0)
                {
                    _syncManager.HeuristicMasterMedia = ssme;
                    _syncManager.RegisterMaster(ssme, ssme.Position);
                    _syncManager.ResetHeuristics();
                }
                else
                {
                    var slave = new SlaveMediaElement
                                    {
                                        IsLogicalSyncEnabled = enableSync,
                                        MediaElement = ssme,
                                        Tolerance = TimeSpan.FromMilliseconds(_settings.SyncToleranceMillis)
                                    };

                    _syncManager.SubMediaElements.Add(slave);
                    if (_syncManager.HeuristicMasterMedia != null)
                    {
                        _syncManager.ResetHeuristics();
                    }
                }
            }
        }