Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm pretty sure that <code>Play</code> is also supposed to handle resume functionality. According to the MSDN for <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer%28v=vs.100%29" rel="nofollow">System.Windows.Media.MediaPlayer</a> the <code>Play</code> method is supposed to "Play media from the current Position". This means that when you are playing media from the beginning, the position is 0. If you pause, then the media will be paused at a certain position. Pressing play again should resume playback from the same position that you paused the media on.</p> <p><strong>Edit:</strong></p> <p>Based on the code update you provided, it looks like your issue is that you are loading the file each time you click play. This would cause any previous pause information to be erased, and would treat the file as being brand new each time. You should put some sort of check in there to say that if the file is not already loaded, then load it. Otherwise, your <code>Play</code> method should just call <code>Player.Play()</code> to resume.</p> <p>I would also note that you would need to also call <code>Player.Close</code> when you switch the selected item. This would let the <code>Play</code> method know that it needs to load a different file.</p> <pre><code>public void Play() { try { // Check if the player already has a file loaded, otherwise load it. if(Player.Source == null) { var audio = Tpv.GetAudio(SelectedTpv.TpvId); var file = Path.GetTempFileName().Replace(".tmp", ".wma"); File.WriteAllBytes(file, audio); Player.Open(new Uri(file, UriKind.Absolute)); } Player.Play(); IsPlaying = true; } catch (Exception ex) { MessageBox.Show(String.Format("Failed to play audio:\n{0}", ex.Message), "Failure", MessageBoxButton.OK, MessageBoxImage.Error); Console.WriteLine(ex.Message); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload