Пример #1
0
        // case1: 当mediaSource为null,newPlayRange不为null时只改变入出点。
        // case2: 当mediaSource不为null,newPlayRange为null时等长替换媒体源。
        // case3: 当mediaSource不为null,newPlayRange不为null时变长替换媒体源。
        private void ChangeMediaSourceInternal(IPlayItem playItem, IMediaSource mediaSource, PlayRange?newPlayRange)
        {
            //if (_playlist.IsLocked(playItem)) throw new PlayItemLockedException();


            if (mediaSource == null && newPlayRange == null)
            {
                return;
            }
            if (mediaSource == null && newPlayRange.Value == playItem.PlayRange)
            {
                return;
            }

            if (newPlayRange != null && (playItem.ScheduleMode == PlayScheduleMode.Timing || playItem.ScheduleMode == PlayScheduleMode.TimingBreak))
            {
                //_playlist.ValidateTimeRange(playItem.StartTime, newPlayRange.Value.Duration, playItem);
                ValidateTimeRange(playItem.StartTime, newPlayRange.Value.Duration, playItem);
            }

            PlayRange playRange = newPlayRange ?? new PlayRange(TimeSpan.Zero, playItem.CalculatedPlayDuration /*playItem.PlayRange.Duration*/);

            if (mediaSource == null)
            {
                mediaSource = playItem.MediaSource; //.Clone();
            }

            var newPlaySource = new PlaySource(mediaSource, playRange, playItem.CGItems);

            IPlayItem newPlayItem = null;

            switch (playItem.ScheduleMode)
            {
            case PlayScheduleMode.Timing:
                newPlayItem = (IPlayItem)PlaybillItem.Timing(newPlaySource, playItem.StartTime);
                break;

            case PlayScheduleMode.TimingBreak:
                newPlayItem = (IPlayItem)PlaybillItem.TimingBreak(newPlaySource, playItem.StartTime);
                break;

            case PlayScheduleMode.Auto:
                newPlayItem = new AutoPlayItem(PlaybillItem.Auto(newPlaySource));
                break;
            }

            var segment = this.FindSegment(playItem);

            DateTime startTime  = segment.StartTime;
            int      beginIndex = segment.BeginIndex;

            DateTime stopTime = segment.StopTime;
            int      endIndex = segment.EndIndex;

            Rebuild(startTime, stopTime, beginIndex, endIndex, (items) =>
            {
                var i    = items.FindIndex(si => si.PlayItem == playItem);
                items[i] = new ScheduleItem(newPlayItem);
            });
        }
Пример #2
0
        internal void ChangePlayRange(IPlayItem playItem, PlayRange newRange)
        {
            int index = _playItems.IndexOf(playItem);

            if (index < 0)
            {
                throw new ArgumentException();
            }

            IPlayItem newPlayItem = null;

            if (playItem.ScheduleMode != PlayScheduleMode.Auto)
            {
                if (newRange.Duration > playItem.PlayRange.Duration)
                {
                    var newStopTime = playItem.StartTime.Add(newRange.Duration);
                    if (this.HasTimingConflict(playItem.StartTime, newStopTime, playItem))
                    {
                        throw new InvalidOperationException();
                    }
                }
                newPlayItem = (IPlayItem)((TimingPlaybillItem)playItem).Clone(newRange);
            }
            else
            {
                newPlayItem = new AutoPlayItem(((AutoPlaybillItem)playItem.PlaybillItem).Clone(newRange));
            }

            _playItems[index] = newPlayItem;
            this.IsDirty      = true;
        }
Пример #3
0
        public void ForcePlay(IPlayItem currentItem, IPlayItem forcedItem)
        {
            this.Delete(forcedItem);

            DateTime stopTime;
            int      beginIndex;

            var startTime    = DateTime.Now.AddSeconds(1.0);
            var currentIndex = _playlist.FindIndex(i => i.PlayItem == currentItem);

            beginIndex = currentIndex + 1;

            Tuple <ScheduleItem, int> temp = FindFirstTiming(beginIndex, (i) => true);
            int endIndex;

            if (temp.Item1 != null)
            {
                stopTime = temp.Item1.StartTime;
                endIndex = temp.Item2 - 1;
            }
            else
            {
                stopTime = DateTime.MaxValue;
                endIndex = _playlist.Count - 1;
            }

            // 调整当前项的播放时长(入出点)


            // 复制当前项,并调整时长。
            var startOffset = startTime.Subtract(currentItem.StartTime);

            var newRange = new PlayRange(currentItem.CalculatedPlayRange.StartPosition + startOffset,
                                         currentItem.CalculatedPlayRange.Duration - startOffset);
            var copyItem = new AutoPlayItem(new AutoPlaybillItem(currentItem.PlaybillItem.PlaySource.Clone(newRange)));



            //if (segment.Head == null)
            //{
            //    startTime = segment.StartTime;
            //    beginIndex = segment.BeginIndex;
            //}
            //else
            //{
            //    startTime = segment.Head.CalculatedStopTime;
            //    beginIndex = segment.BeginIndex + 1;
            //}

            //stopTime = segment.StopTime;
            //endIndex = segment.EndIndex;

            this.Rebuild(startTime, stopTime, beginIndex, endIndex, (items) =>
            {
                // 插入复制项和forcedItem。
                items.Insert(0, new ScheduleItem(copyItem));
                items.Insert(0, new ScheduleItem(forcedItem));
            });
        }
Пример #4
0
        public override IPlaybillItem Clone(PlayRange newRange)
        {
            var result = new AutoPlaybillItem(this.PlaySource.Clone(newRange));

            result.IsAutoPadding = this.IsAutoPadding; // ?
            result.Id            = Guid.NewGuid();
            return(result);
        }
Пример #5
0
 public PlaySource(IMediaSource mediaSource, PlayRange playRange, CGItemCollection cgItems)
     : this(mediaSource, playRange)
 {
     if (cgItems != null)
     {
         this.CGItems = cgItems.Clone();
     }
 }
Пример #6
0
        //IPlayItem IPlayItem.Clone()
        //{
        //    return (IPlayItem)this.Clone();
        //}

        //protected override PlaybillItem Clone()
        //{
        //    var result= new TimingPlaybillItem(this.PlaySource.Clone(),
        //        this.StartTime.Value, this.ScheduleMode == PlayScheduleMode.TimingBreak);
        //    result.Id = this.Id;
        //    return result;
        //}

        //public override IPlaybillItem Clone(PlayRange newRange)
        //{
        //    throw new NotImplementedException();
        //}

        public override IPlaybillItem Clone(PlayRange newRange)
        {
            var newSource = this.PlaySource.Clone(newRange);
            var result    = new TimingPlaybillItem(newSource, this.StartTime.Value, this.ScheduleMode == PlayScheduleMode.TimingBreak ? true: false);

            result.Id = Guid.NewGuid();
            return(result);
        }
Пример #7
0
 internal static void ValidatePlayRange(this IMediaSource mediaSource, PlayRange playRange)
 {
     if (mediaSource.Duration != null)
     {
         if (playRange.StartPosition > mediaSource.Duration.Value || playRange.StopPosition > mediaSource.Duration.Value)
         {
             throw new InvalidPlayRangeException(playRange);
         }
     }
 }
Пример #8
0
        public PlaySource(IMediaSource mediaSource, PlayRange playRange)
        {
            if (mediaSource.Duration != null)
            {
                PlayoutUtils.ValidatePlayDuration(playRange.Duration);
            }

            //mediaSource.ValidatePlayRange(playRange);
            this.MediaSource = mediaSource;
            this.PlayRange   = playRange;
        }
Пример #9
0
        public IPlaySource Clone(PlayRange newRange)
        {
            var result = new PlaySource(this.MediaSource, newRange);

            if (this.CGItems != null)
            {
                result.CGItems = this.CGItems.Clone();
            }

            return(result);
        }
Пример #10
0
 /// <summary>
 /// 变长替换媒体源。
 /// </summary>
 /// <param name="playItem"></param>
 /// <param name="mediaItem"></param>
 public void ChangeMediaSource(IPlayItem playItem, IMediaSource mediaSource, PlayRange playRange)
 {
     this.ChangeMediaSourceInternal(playItem, mediaSource, playRange);
 }
Пример #11
0
 public abstract IPlaybillItem Clone(PlayRange newRange);
Пример #12
0
 public PlayRange?Adjust(PlayRange playRange)
 {
     return(new PlayRange(playRange.Duration));
 }
Пример #13
0
 public PlayRange?Adjust(PlayRange playRange)
 {
     throw new NotSupportedException();
 }
Пример #14
0
 public InvalidPlayRangeException(PlayRange playRange)
 {
     this.PlayRange = playRange;
 }
Пример #15
0
 // 用于创建顺播片断。
 private AutoPlayItem(IPlaybillItem billItem, PlayRange playRange) : this(billItem)
 {
     this.PlayRange = playRange;
 }
Пример #16
0
 public MediaItem(IMediaSource source, PlayRange playRange)
 {
     source.ValidatePlayRange(playRange);
     this.Source    = source;
     this.PlayRange = playRange;
 }
Пример #17
0
 /// <summary>
 /// 修改媒体源的入出点。
 /// </summary>
 /// <param name="playItem"></param>
 /// <param name="newRange"></param>
 public void ChangePlayRange(IPlayItem playItem, PlayRange newRange)
 {
     this.ChangeMediaSourceInternal(playItem, null, newRange);
 }