I want to play an MP3 file for a certain duration, starting at a certain position, in a WPF app. I want to do this in the code-behind (C#) not the XAML.
In my handler for the "Play" button, I can set the duration easily like this (5000 ms just for example)
myTimeLine.Source = _MyMediaElement.Source;
myTimeLine.Duration = (TimeSpan.FromMilliseconds(5000));
MediaClock mc = myTimeLine.CreateClock();
_MyMediaElement.Clock = mc;
Or I can set the starting position easily like this . . .
_MyMediaElement.Position = (TimeSpan.FromMilliseconds(5000));
But I can"t do both or I'll get a "Can not perform this operation while a clock is assigned to the media player
" exception. What's the correct solution to this? Thanks in advance!!