/// <summary> /// Raises the <see cref="PositionUpdated"/> event and sets /// the current mediadata when the current mediadata reaches to end. /// the current mediadata when the current mediadata reaches to end. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void OnFrameRendered(object sender, EventArgs e) { this.timer.Stop(); if (!this.IsPlaying) { return; } TimeSpan currentPosition = this.Position; TimeSpan off = TimeSpan.FromSeconds(0); TimeSpan outPosition = TimeSpan.FromSeconds(0); for (int i = 0; i < this.currentMedia.Count; i++) { if (this.currentMedia[i] >= 0 && this.currentMedia[i] < this.mediaData.Count) { MediaData m = this.mediaData[this.currentMedia[i]]; if (m.Position.TotalSeconds >= m.Out.TotalSeconds || !m.Playing) { off = m.Position.Subtract(m.Out); outPosition = TimeSpan.FromSeconds(m.TimelineElement.Position.TotalSeconds + m.Out.TotalSeconds); if (off.Ticks < 0) { off = TimeSpan.FromSeconds(0); } m.Hide(); } } } TimeSpan newPosition = currentPosition + off; IList <int> nextCurrentMedia = this.NextCurrentMedia(newPosition); if (nextCurrentMedia.Count != this.currentMedia.Count || nextCurrentMedia.Except(this.currentMedia).Count() > 0) { if (newPosition > this.Position) { this.Position = newPosition; } foreach (int i in this.currentMedia) { MediaData m = this.mediaData[i]; m.Show(); m.Play(); } } if (this.currentMedia.Count == 0) { this.IsPlaying = false; this.OnFinishedPlaying(); this.Position = outPosition; } this.OnPositionUpdated(this.Position); this.timer.Start(); // if (FrameRendered != null) FrameRendered(this, null); }