Example #1
0
        private void PlayTrack(object o)
        {
            var track = o as TrackListModel;

            CurrentTrack = track;
            _trackIndex  = TrackModelList.IndexOf(track);
            MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
            MyMediaElement.Stop();
            Position = 0;
            Thread.Sleep(100);
            StartTime = "0:00";
            IsPlay    = true;
            ChangePlayState(true);
        }
Example #2
0
        private void MyMediaElementOnMediaOpenedPreview(object sender, EventArgs eventArgs)
        {
            var duration =
                $"{MyMediaElement.NaturalDuration.TimeSpan.Minutes}:{GetCorrectSeconds(MyMediaElement.NaturalDuration.TimeSpan.Seconds)}";
            var path = MyMediaElement.Source.OriginalString;

            if (path == TrackModelList.Last().Path)
            {
                MyMediaElement.MediaOpened -= MyMediaElementOnMediaOpenedPreview;
                MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
                MyMediaElement.Stop();
                MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened;
                MyMediaElement.MediaEnded  += MyMediaElementOnMediaEnded;
                MyMediaElement.Volume       = Volume;
            }

            TrackModelList.First(x => x.Path == path).Duration = duration;
        }