public Player(
        MediaElement vid,
        MseStreamSource mse,
        Manifest manifest)
        {
            sourceBuffers = new List<SourceBufferManager>();
            playbackTimer = new DispatcherTimer();
            mediaElement = vid;
            this.mse = mse;
            this.manifest = manifest;

            //Add an audio and video source buffer
            AddAudioAndVideoSourceBuffers(this.manifest.GetSelectedPeriod());
            
            if (this.manifest.IsLive && this.manifest.HasMinimumUpdatePeriod)
            {
                StartManifestReloadTimer();
            }

        }
        internal async void GoToLiveEdge()
        {
            await ReloadManifest();

            sourceBuffers.Clear();
            mse.EndOfStream(MseEndOfStreamStatus.Success);

            opened = false;
            mse = new MseStreamSource();
            AddAudioAndVideoSourceBuffers(manifest.GetSelectedPeriod());

            SetLiveOffsetValue();
            
            ConfigureMse();
            mediaElement.SetMediaStreamSource(mse);
            
            CheckForMediaPresentationDuration();
            UpdateLiveSourceBuffersToLiveEdge();
            mediaElement.Play();
        }
        internal void Close()
        {
            try
            {
                if (manifestReloadTimer != null)
                {
                    manifestReloadTimer.Stop();
                }
                sourceBuffers.Clear();
                mse = null;
                playbackTimer.Stop();
            }
            catch (Exception e)
            {
#if DEBUG
                Logger.Log("Exception has been thrown: " + e.Message);
#endif
            }
        }
        private void M_mse_Opened(MseStreamSource sender, object args)
        {
#if DEBUG
            Logger.Log("Opened Stream Source");
#endif
            if (opened)
            {
                return;
            }
            opened = true;
            foreach (var sourceBuffer in sourceBuffers)
            {
                if (manifest.IsLive)
                {
                    mse.Duration = null;
                }
                sourceBuffer.Initialize(mse);
            }
    }
        private void M_mse_Closed(MseStreamSource sender, object args)
        {
#if DEBUG
            Logger.Log("Closing media source");
#endif
            foreach (var sourceBuffer in sourceBuffers)
            {
                sourceBuffer.Close();
            }

        }
        /// <summary>
        /// Downloads the manifest from the given source, parses the manifest
        /// and sets the source on the media element 
        /// </summary>
        /// <param name="source">The URL of the source MPD</param>
        /// <param name="mediaElement">The MediaElement to start playback</param>
        /// <returns></returns>
        public async Task Initialize(Uri source, MediaElement mediaElement)
        {
            //1) Download manifest
            var sourceUrlText = source.AbsoluteUri;
            try
            {
                var manifest = new Manifest(sourceUrlText);
                var document = await manifest.LoadManifestAsync(sourceUrlText);

                //2) Parse manifest
                DashManifestParser mpdParser = new DashManifestParser(document, ref manifest);
                if (mpdParser.Parse())
                {

                    if (!manifest.IsSupportedProfile)
                    {
#if DEBUG
                        Logger.Log("The profiles attribute does not contain the \"urn:mpeg:dash:profile:isoff-live:2011\" profile, so it may not work as expected.");
#endif
                    }
                    if (manifest.IsLive)
                    {
                        //3) Play using MSE if it is live
                        MseStreamSource mseSource = new MseStreamSource();
                        player = new Player(mediaElement, mseSource, manifest);
                        if (haveSetLiveOffset && manifest.IsLive)
                        {
                            player.HasLiveOffsetValue = true;
                            player.LiveOffset = liveOffset;
                        }
                        player.Initialize();
                    }
                    else
                    {
                        // Otherwise, use our Adaptive Media Source for on demand content
                        var result = await AdaptiveMediaSource.CreateFromUriAsync(source);
                        if (result.Status != AdaptiveMediaSourceCreationStatus.Success)
                        {
                            throw new Exception("Unable to create media source because: " + result.Status);
                        }
                        var adaptiveSource = result.MediaSource;

                        mediaElement.SetMediaStreamSource(adaptiveSource);
                        mediaElement.Play();
                    }


                }

                else
                {
#if DEBUG
                    Logger.Log("The Parser failed to parse this mpd");
#endif
                    return;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Logger.Log("Exception when initializing player: " + e.Message + " " + Logger.Display(e));
#endif
            }
        }
 internal void Initialize(MseStreamSource mse)
 {
     this.mse = mse;
     sb = this.mse.AddSourceBuffer(mimeType);
 }
 public MseStreamSourceEvents(MseStreamSource This)
 {
     this.This = This;
 }