Esempio n. 1
0
        internal MediaSegment GetNextSegment()
        {
            DetermineStartingSegmentIndex();
            bool isEndOfStream = false;

            if (manifest.HasPresentationDuration)
            {
                if (isFirstSegment)
                {
                    var segmentInfo          = stream.SegmentInformation;
                    var presentationDuration = (ulong)manifest.MediaPresentationDuration.TotalMilliseconds * segmentInfo.Timescale / 1000;

                    var segmentDuration = segmentInfo.Duration;

                    totalSegmentCount = (int)presentationDuration / (int)segmentDuration;
                }
            }

            MediaSegment segment;

            if (stream.CanGenerateSegmentsDynamically && !isEndOfStream)
            {
                //create new segment based on media segment info given
                segment = new MediaSegment();
                var segmentInfo = stream.SegmentInformation;

                var format  = segmentInfo.UrlTemplate;
                var bitrate = segmentInfo.Bitrate;
                var repID   = segmentInfo.RepresentationID;
                var number  = segmentInfo.StartNumber + (ulong)nextSegmentIndex;
                var time    = segmentInfo.StartTimestamp + (ulong)nextSegmentIndex;

                string mediaUrl;
                DashManifestParser.ExpandDASHUrlSegmentTemplate(format, manifest.BaseUrl, bitrate, repID, number, time, out mediaUrl);

                segment.Duration   = segmentInfo.Duration;
                segment.Number     = number;
                segment.Timestamp  = time;
                segment.SegmentUrl = mediaUrl;
            }
            else //populated by a list of segments
            {
                segment = stream.Segments.ElementAt(nextSegmentIndex);
            }
            nextSegmentNumber = segment.Number + 1;

            return(segment);
        }
Esempio n. 2
0
        private async Task <bool> ReloadManifest()
        {
            try
            {
                //Redownload manifest to pick up where it left off
                var mpdUrl = manifest.SourceUrl;
                manifest = new Manifest(mpdUrl);
                var document = await manifest.LoadManifestAsync(mpdUrl);

                DashManifestParser mpdParser = new DashManifestParser(document, ref manifest);

                return(mpdParser.Parse());
            }
            catch (Exception e)
            {
#if DEBUG
                Logger.Log("Error reloading manifest in the Live Source Buffer: " + e.Message);
#endif
                return(false);
            }
        }
        private async Task ReloadManifest()
        {
            try
            {
                var sourceUrl = manifest.SourceUrl;
                manifest = new Manifest(sourceUrl);
                var document = await manifest.LoadManifestAsync(sourceUrl);

                DashManifestParser mpdParser = new DashManifestParser(document, ref manifest);
                if (!mpdParser.Parse())
                {
#if DEBUG
                    Logger.Log("The Parser failed to parse this mpd");
#endif
                    return;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Logger.Log("Error occured reloading manifest: " + e.Message);
#endif
            }
        }
Esempio n. 4
0
        /// <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
            }
        }
Esempio n. 5
0
        private async Task <DashManifestParser> GetDashManifestParserAsync(string dashManifestUrl)
        {
            var raw = await _httpClient.GetStringAsync(dashManifestUrl);

            return(DashManifestParser.Initialize(raw));
        }