Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:

C#
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

Try:
C#
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();
                    }
                 }
 
Share this answer
 
Comments
DominicZA 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...
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):"

C#
this.currentPosition = this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) + this.startPosition;
this.wavParser.MoveToChunkOffset( ( uint ) this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) );
this.currentTimeStamp = seekToTime;
ReportSeekCompleted( seekToTime );
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900