private async void DoTrackStart()
        {
            await Task.Delay(100).ConfigureAwait(false);

            if (partPlayStart != TimeSpan.Zero)
            {
                //await Task.Delay(100);
                //  PlayerStoryboard.BeginTime = MarkerStoryboard.BeginTime = partPlayStart;
                if (PlayPartLength > 0)
                {
                    var end = (TimeSpan.FromMilliseconds(PlayPartLength + partPlayStart.TotalMilliseconds));
                    endAnimationTime = end;
                    // PlayerStoryboard.Duration = MarkerStoryboard.Duration = (TimeSpan.FromMilliseconds(PlayPartLength + partPlayStart.TotalMilliseconds));
                    //PlayerStoryboard.SpeedRatio = 0.5;
//                    playTimer = new System.Threading.Timer(doTrackPartEnd, partPlayStart, (int)PlayPartLength, Timeout.Infinite);
                }
                else
                {
                    endAnimationTime = null;
                    partPlayStart    = TimeSpan.Zero;
                }

                PlayerStoryboard.Resume(mediaElement);
                MarkerStoryboard.Resume(PositionBar);
            }
            else
            {
                PlayerStoryboard.Begin(mediaElement, true);
                MarkerStoryboard.Begin(PositionBar, true);
            }
        }
        private void DoPlayTextPart(TextPart tp)
        {
            PlayerStoryboard.Stop(mediaElement);
            MarkerStoryboard.Stop(PositionBar);

            PlayPartLength = tp.TextWidth; // 1px = 1 mill
            var scaledStartMills = tp.StartMills;

            var seekTime = TimeSpan.FromMilliseconds(scaledStartMills);

            MarkerRectangle.Margin = new Thickness(scaledStartMills * Scale, 0, 0, 0);
            MarkerRectangle.Width  = PlayPartLength * Scale;
            SeekToMousePointInTime(seekTime);
            TrackStartCommand.Execute(null);
        }
        internal void SeekToMousePointInTime(TimeSpan seekTime)
        {
            if (seekTime.Ticks < 0)
            {
                seekTime = TimeSpan.FromTicks(1);
            }
            partPlayStart = seekTime;

            MarkerStoryboard.Begin(PositionBar, true);  // if the second parameter is missing or false, it doesn't work
            MarkerStoryboard.Seek(PositionBar, seekTime, TimeSeekOrigin.BeginTime);
            MarkerStoryboard.Pause(PositionBar);        // stop doesn't work

            PlayerStoryboard.Begin(mediaElement, true); // if the second parameter is missing or false, it doesn't work
            PlayerStoryboard.Seek(mediaElement, seekTime, TimeSeekOrigin.BeginTime);
            PlayerStoryboard.Pause(mediaElement);       // stop doesn't work
        }
 private void DoTrackPause()
 {
     if (!IsPaused)
     {
         Debug.WriteLine("Audio player was not paused");
         PlayerStoryboard.Pause(mediaElement);
         IsPaused = true;
         Debug.WriteLine("Audio player now paused");
     }
     else
     {
         Debug.WriteLine("Audio player was paused");
         PlayerStoryboard.Resume(mediaElement);
         IsPaused = false;
         Debug.WriteLine("Audio player now unpaused");
     }
 }
        private void Storyboard_Changed(object sender, EventArgs e)
        {
            if (endAnimationTime == null)
            {
                return;
            }

            ClockGroup clockGroup = sender as ClockGroup;

            if (clockGroup != null)
            {
                MediaClock mediaClock = clockGroup.Children[0] as MediaClock;
                if (mediaClock.CurrentProgress.HasValue)
                {
                    if (mediaClock.CurrentTime >= endAnimationTime)
                    {
                        PlayerStoryboard.Pause(mediaElement);
                    }
                }
            }
        }
 private void DoTrackStop()
 {
     PlayerStoryboard.Stop(mediaElement);
 }