How to play an audio file is not from the beginning

168 views Asked by At

In my project, I use WPFMediaKit to play audio files in the format: myAudioFile.m3u8 which contains a list of links to myAudio1.ts, myAudio2.ts, etc.

I start playing files like this code:

    ...
   _player.Source = trackUri;

   _player.Dispatcher.Invoke((Action) (() =>
   {
       _player.Play();
       _player.MediaPosition = 100000000; // in ticks, doesn't work at this place 
   }));
   ...

In some cases, I need to start playing files not from the beginning, but for example from 10 seconds of playing.

How can I do that?

1

There are 1 answers

1
MakS On BEST ANSWER

Thanks to rene!
Set PreferedPositionFormat to MediaPositionFormat.MediaTime, before the position is changed. In most cases this is enough.

...
_player.Source = trackUri;

_player.Dispatcher.Invoke((Action) (() =>
{
   _player.Play();
   _player.PreferedPositionFormat = MediaPositionFormat.MediaTime;
   _player.MediaPosition = 100000000; // in ticks, doesn't work at this place 
}));
...