Click here to Skip to main content
12,504,695 members (58,875 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Silverlight
I have a media element which I give a source I get from Microsofts translation service. This is a slight problem because it gives me a wav file. I used the WAVmss library to help me and it works great, but for one thing. It plays the first time I load the file into the element, but when I try and play it a second time it doesn't play? The playback code could not be simpler:

private void Play()
        {
            mediaElement.Stop();
            mediaElement.Position = TimeSpan.Zero;
            mediaElement.Play();
        }

I have debugged. The Position property does get set to zero, ,and when I break in after clicking it again its position has moved to the end.

An ideas?
Posted 31-Jul-11 23:03pm
DominicZA4.1K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try:
if (mediaElement.CurrentState == MediaElementState.Playing)
                {
                    mediaElement.Pause();
                }
                else
                {
                    if (mediaElement.CurrentState == MediaElementState.Paused)
                    {
                        if (mediaElement.Position == mediaElement.NaturalDuration.TimeSpan)
                        {
                            mediaElement.Position = new TimeSpan(0);
                        }
                        mediaElement.Play();
                    }
                 }
  Permalink  
Comments
dominic_nologo 1-Aug-11 7:22am
   
Thanks random person! But I am still having the same problem. Your code is not that much different to mine...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I had the same issue and thanks to Gilles Khouzam quick response the problem has been solved.

"Ok, I found the issue. The implementation of SeekAsync, the position in the stream was changed but the remaining count in the chunk was not. In WaveMediaStreamSource.cs, look for the SeekAsync method and change the code to this (add the MoveToChunkOffest line):"

this.currentPosition = this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) + this.startPosition;
this.wavParser.MoveToChunkOffset( ( uint ) this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) );
this.currentTimeStamp = seekToTime;
ReportSeekCompleted( seekToTime );
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100