internal void ChangeSource(IPlayItem playItem, IMediaSource newSource, PlayRange?newRange) { int index = _playItems.IndexOf(playItem); if (index < 0) { throw new ArgumentException(); } IPlayItem newPlayItem = null; if (newRange != null && playItem.ScheduleMode != PlayScheduleMode.Auto) { if (newRange.Value.Duration > playItem.PlayRange.Duration) { var newStopTime = playItem.StartTime.Add(newRange.Value.Duration); if (this.HasTimingConflict(playItem.StartTime, newStopTime, playItem)) { throw new InvalidOperationException(); } } } else { } newRange = newRange == null ? new PlayRange(TimeSpan.Zero, playItem.CalculatedPlayDuration) : newRange.Value; var newPlaySource = new PlaySource(newSource, newRange.Value, playItem.PlaybillItem.PlaySource.CGItems); switch (playItem.ScheduleMode) { case PlayScheduleMode.Auto: newPlayItem = new AutoPlayItem(AutoPlaybillItem.Auto(newPlaySource)); break; case PlayScheduleMode.Timing: newPlayItem = (IPlayItem)TimingPlaybillItem.Timing(newPlaySource, playItem.StartTime); break; case PlayScheduleMode.TimingBreak: newPlayItem = (IPlayItem)TimingPlaybillItem.TimingBreak(newPlaySource, playItem.StartTime); break; } _playItems[index] = newPlayItem; this.IsDirty = true; }
internal void ChangeStartTime(DateTime newStartTime) { if (_playItems[0].ScheduleMode != PlayScheduleMode.Timing) { throw new InvalidOperationException(); } var newStopTime = newStartTime.Add(_playItems[0].PlaybillItem.PlayRange.Duration); var prevSegment = this.Previous; if (newStartTime < this.StartTime) { if (prevSegment != null) { if (prevSegment.HasTimingConflict(newStartTime, newStopTime)) { throw new InvalidOperationException("定时播或定时插播之间有时间冲突。"); } for (int i = prevSegment._playItems.Count - 1; i >= 0; i--) { var item = prevSegment._playItems[i]; if (item.ScheduleMode == PlayScheduleMode.TimingBreak) { if (item.StartTime >= newStartTime) { this._playItems.Insert(1, item); //AddNewTimingBreakItem(item); prevSegment._playItems.Remove(item); } else { break; } } } } } else //newStartTime > this.StartTime { if (this.HasTimingConflict(newStartTime, newStopTime, _playItems[0])) { throw new InvalidOperationException("定时播或定时插播之间有时间冲突。"); } for (int i = this._playItems.Count - 1; i >= 0; i--) { var item = this._playItems[i]; if (item.ScheduleMode == PlayScheduleMode.TimingBreak) { if (item.StartTime < newStartTime) { if (prevSegment == null) { throw new InvalidOperationException(); } prevSegment._playItems.Add(item); //prevSegment.AddNewTimingBreakItem(item); this._playItems.Remove(item); } } } } var playSource = _playItems[0].PlaybillItem.PlaySource; _playItems[0] = (TimingPlaybillItem)TimingPlaybillItem.Timing(playSource, newStartTime); if (prevSegment != null) { prevSegment.IsDirty = true; } this.IsDirty = true; }