none
Only plays the sound once, what have I done wrong?

    Question

  • I've got a media element, created programmatically, that has an mp3 file as the source. When I press my play button it plays the sound fine. However, when I press play subsequent times it doesn't play. Examining the state of the media element it says 'paused' after I press the play. Any ideas what I'm doing wrong?

     

    this.mediaElement.Stop();
    this.mediaElement.Position = new TimeSpan(0);
    System.Diagnostics.Debug.WriteLine(this.mediaElement.CurrentState);
    this.mediaElement.Play();
     
    Sunday, August 31, 2008 5:45 AM

Answers

  • Is it a very short sound? There are issues with mp3s where the beginning can get clipped and if it's a short sound it might not play at all. The only good workaround I've seen at this point is to put a second or so of "dead air" in the sound at the beginning so if it gets clipped it will be the dead air that gets clipped. Hopefully this will be fixed for the release.

    You also shouldn't need to set the position after a Stop() call, Stop should automatically set the position to 0.

    Sunday, August 31, 2008 7:38 AM

All replies

  • Is it a very short sound? There are issues with mp3s where the beginning can get clipped and if it's a short sound it might not play at all. The only good workaround I've seen at this point is to put a second or so of "dead air" in the sound at the beginning so if it gets clipped it will be the dead air that gets clipped. Hopefully this will be fixed for the release.

    You also shouldn't need to set the position after a Stop() call, Stop should automatically set the position to 0.

    Sunday, August 31, 2008 7:38 AM
  • I came to the same conclusion myself and converted the mp3 to wma and everything is fine. I saw your post as I was posting this so I think you're correct there is a problem with small mp3s. The stop and position was me trying everything, but it's good to know stop resets it. So the moral of the story is, don't use small mp3s!

     

    Sunday, August 31, 2008 8:36 AM
  • Unable to play .wma.  Do I really need to use Expression Encoder to make a real working .wma ?

    The one I'm using is a 9.2

     

    Sunday, October 26, 2008 6:13 PM
  • Here's a screenshot of my wma sound and it's a very short sound but nothing plays.

    No sound...

    Sunday, October 26, 2008 6:26 PM
  • Have you tried a larger file to ensure that it isn't just your code? I'm not aware of any special encoding I just converted the mp3 to wma

    Monday, October 27, 2008 5:48 AM
  • Ok I did reply on a similar thread.  I found why and it was my fault.  I wasn't adding the sound to the children.  I was trying to play the sound directly :)

    Now with :

    ((MediaElement)this.LayoutRoot.Children.FindName("Audio")).Stop();
    ((MediaElement)this.LayoutRoot.Children.FindName("Audio")).Play();

    it works fine.  Well, almost fine.  We still have the bug that Microsoft seems to be aware of which is the first time the sound is played is good but the other times, the sound is stitchy and seems to be cut off at some point in time.

    Perfect example of this : http://gearworld.dyndns.org:8082/devpreview.  Click the orange ball in the upper right corner

     

    Monday, October 27, 2008 7:03 AM