public static PlayRange Adjust(this IMediaSource mediaSource, PlayRange playRange)
 {
     if (!mediaSource.HasNativeDuration())
     {
         playRange = new PlayRange(playRange.Duration);
     }
     mediaSource.ValidatePlayRange(playRange);
     return(playRange);
 }
 private static bool IsValidPlayRange(this IMediaSource mediaSource, PlayRange playRange)
 {
     if (mediaSource.HasNativeDuration())
     {
         return(mediaSource.GetNativePlayRange().Include(playRange));
     }
     else
     {
         return(playRange.StartPosition == TimeSpan.Zero);
     }
 }
        internal PlayRange Adjust(PlayRange range)
        {
            range = this.MediaSource.Adjust(range);
            if (!this.PlayRange.Include(range))
            {
                throw new ArgumentOutOfRangeException("range",
                                                      string.Format("<{0}>无效,有效范围为{1}。", range, this.PlayRange));
            }

            return(range);
        }
Example #4
0
        internal static PlayRange Adjust(this IPlaySource playSource, PlayRange playRange)
        {
            var range = playSource.MediaSource.Adjust(playRange);

            if (!playSource.PlayRange.Include(range))
            {
                throw new ArgumentOutOfRangeException("playRange",
                                                      string.Format("<{0}>无效,有效范围为{1}。", playRange, playSource.PlayRange));
            }

            return(range);
        }
Example #5
0
        internal NormalPlaySource(IMediaSource mediaSource, PlayRange range)
        {
            if (mediaSource == null)
            {
                throw new ArgumentNullException("mediaSource");
            }

            range = mediaSource.Adjust(range);

            this.MediaSource = mediaSource;
            this.PlayRange   = range;
        }
Example #6
0
            internal PlaySource Merge(PlaySource nextSource)
            {
                if (!CanMerge(nextSource))
                {
                    throw new InvalidOperationException();
                }

                PlayRange range = this.MediaSource.Merge(this.PlayRange, ((PlaySourceSegment)nextSource).PlayRange);

                range = this.PlaySource.Adjust(range); // 确保范围不超出this.PlaySource.PlayRange

                return(Create(this.PlaySource, range));
            }
Example #7
0
        internal static void Break(this PlaySource playSource, TimeSpan duration, out PlayRange first, out PlayRange second)
        {
            if (duration <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("duration",
                                                      string.Format("<{0}>无效,必须大于TimeSpan.Zero。", duration));
            }
            if (duration >= playSource.PlayRange.Duration)
            {
                throw new ArgumentOutOfRangeException("duration",
                                                      string.Format("<{0}>无效,必须小于{1}。", duration, playSource.PlayRange.Duration));
            }

            PlayRange.Break(playSource.PlayRange, duration, out first, out second);

            first  = playSource.Adjust(first);
            second = playSource.Adjust(second);
        }
Example #8
0
            public static PlaySource Create(NormalPlaySource playSource, PlayRange playRange)
            {
                // Note: 是否在自动垫片上操作?

                if (playSource == null)
                {
                    throw new ArgumentNullException("playSource");
                }

                playRange = playSource.Adjust(playRange);

                if (playRange == playSource.PlayRange)
                {
                    return(playSource);
                }

                return(new PlaySourceSegment(playSource, playRange));
            }
 private static void ValidatePlayRange(this IMediaSource mediaSource, PlayRange playRange)
 {
     if (!mediaSource.IsValidPlayRange(playRange))
     {
         if (mediaSource.HasNativeDuration())
         {
             throw new ArgumentException(
                       string.Format("{0}无效,有效范围为:{1}。", playRange, mediaSource.GetNativePlayRange()),
                       "playRange");
         }
         else
         {
             throw new ArgumentException(
                       string.Format("{0}无效,起始位置必须为TimeSpan.Zero。", playRange),
                       "playRange");
         }
     }
 }
        internal static PlayRange Merge(this IMediaSource mediaSource, PlayRange first, PlayRange second)
        {
            if (!mediaSource.CanMerge(first, second))
            {
                throw new InvalidOperationException();
            }

            first  = mediaSource.Adjust(first);
            second = mediaSource.Adjust(second);

            if (mediaSource.HasNativeDuration())
            {
                return(PlayRange.Merge(first, second));
            }
            else
            {
                return(new PlayRange(first.Duration + second.Duration));
            }
        }
        //public TimeSpan? NativeDuration
        //{
        //    get
        //    {
        //        return this.MediaSource.NativeDuration;
        //    }
        //}

        public MarkableMediaSource(IMediaSource mediaSource, PlayRange playRange)
        {
            if (mediaSource == null)
            {
                throw new ArgumentNullException("mediaSource");
            }


            var adjustedPlayRange = mediaSource.Adjust(playRange); // 包含对playRange有效性的验证

            //MarkableMediaSource markable = mediaSource as MarkableMediaSource;
            //if (markable!=null)
            //{
            //    this.MediaSource = markable.MediaSource;
            //}
            //else
            //{
            //    this.MediaSource = mediaSource;
            //}

            this.MediaSource = mediaSource;
            this.PlayRange   = adjustedPlayRange;
        }
Example #12
0
 private PlaySourceSegment(NormalPlaySource playSource, PlayRange playRange)
 {
     this.PlayRange  = playRange;
     this.PlaySource = playSource;
 }
 internal static bool CanMerge(this IMediaSource mediaSource, PlayRange first, PlayRange second)
 {
     return(mediaSource.HasNativeDuration() ?
            PlayRange.IsUnbroken(mediaSource.Adjust(first), mediaSource.Adjust(second)) : true);
 }