SL media item won't play my wave file after the first time

I am using the WaveMediaStreamSource (WAVmss) library to play wave files in a silverlight media element.
It plays the first time I load the file into the element, but when I try to play it the second time it doesn't play.
I used a sample here .

Maybe I missed something, here is my code where I open the wave file and successfully run it the first time. Here is a file reading and setting as source in my media item:

OpenFileDialog openFileDialog = new OpenFileDialog();    
MemoryStream audioSource = new MemoryStream();

if (openFileDialog.ShowDialog() == true)    
{    
   using (FileStream fileStream = openFileDialog.File.OpenRead())    
   {    
       audioSource.SetLength(fileStream.Length);    
       fileStream.Read(audioSource.GetBuffer(), 0, (int)fileStream.Length);    
   }    
}

WaveMSS.WaveMediaStreamSource audioStreamSource = 
                 new WaveMSS.WaveMediaStreamSource(audioSource);

mediaElement1.SetSource(audioStreamSource);

      

And when the first game is over (I know this since I receive the event _MediaEnded

), I cannot play that video again.

I tried to set the position of the MediaElement, but couldn't play it again:

mediaElement1.Position = TimeSpan.FromSeconds(0);
mediaElement1.Play();

      

I debugged it and the Position property goes to zero, but when I try to click again, the position property moves to the end and the event _MediaEnded

appears again.

What can I do?

+3


source to share


2 answers


Thanks to Gilles Khouzam, the quick response has solved the problem.

Ok I found the problem. SeekAsync implementation, the position in the stream was changed, but the remaining amount in the chunk was not. In WaveMediaStreamSource.cs find 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 );

      

+1


source


In the MediaEnded event, send a "sender" to the MediaElement and call Stop (). This resets the object so you can play it again.



0


source







All Articles