예제 #1
0
        public TimeSpan Seek(TimeSpan position)
        {
            // A workaround for a case when we seek to the end of a content while audio and video streams have
            // a slightly different duration.
            if (position > currentStreams.Duration)
            {
                position = (TimeSpan)currentStreams.Duration;
            }

            currentSegmentId = currentStreams.SegmentId(position);
            var previousSegmentId = currentStreams.PreviousSegmentId(currentSegmentId);

            lastDownloadSegmentTimeRange = currentStreams.SegmentTimeRange(previousSegmentId);

            var seekToTimeRange = currentStreams.SegmentTimeRange(currentSegmentId);

            // We are not expecting NULL segments after seek.
            // Termination will occur after restarting
            if (seekToTimeRange == null)
            {
                LogError($"Seek Pos Req: {position} failed. No segment/TimeRange found");
                currentTime = position;
                return(currentTime);
            }

            currentTime = seekToTimeRange.Start;

            LogInfo(
                $"Seek Pos Req: {position} Seek to: ({seekToTimeRange.Start}/{currentTime}) SegId: {currentSegmentId}");

            return(seekToTimeRange.Start);
        }
예제 #2
0
        public TimeSpan Seek(TimeSpan position)
        {
            // A workaround for a case when we seek to the end of a content while audio and video streams have
            // a slightly different duration.
            if (position > currentStreams.Duration)
            {
                position = (TimeSpan)currentStreams.Duration;
            }

            currentSegmentId = currentStreams.SegmentId(position);
            var previousSegmentId = currentStreams.PreviousSegmentId(currentSegmentId);

            lastDownloadSegmentTimeRange = currentStreams.SegmentTimeRange(previousSegmentId);

            var seekToTimeRange = currentStreams.SegmentTimeRange(currentSegmentId);

            // We are not expecting NULL segments after seek.
            // Termination will occur after restarting
            if (seekToTimeRange == null)
            {
                LogError($"Seek Pos Req: {position} failed. No segment/TimeRange found");
                throw new ArgumentOutOfRangeException();
            }

            // Seek operation clears all buffered data (bufferTime=0). bufferTime is set to currentTime
            // during Start(). bufferTime will get updated after chunk download.
            currentTime = TimeSpan.Zero;

            // Clear dataClockLimit. Download will start after new dataClockLimit is
            // received.
            _dataClockLimit = TimeSpan.Zero;

            LogInfo(
                $"Seek Pos Req: {position} Seek to: ({seekToTimeRange.Start}-{seekToTimeRange.Start + seekToTimeRange.Duration}/{currentTime}) SegId: {currentSegmentId}");

            return(seekToTimeRange.Start);
        }