Search code examples
silverlightwindows-phone-7mediaelement

MediaElement is repeating clips automatically, and sometimes fails to play them


I have an app which plays a few short sound clips. To play them I simply set the source to the new clip path, which is a WMA I encoded with Expression Encoder using WP7 settings. It's not even worth sharing the code -- there's an event handler. In it, I set the ME.Source property to a new Uri. It's set to AutoPlay, so that's it! Here:

    private void PlaySound(ItemViewModel sound) {
        Model.CurrentSound = sound;
        CurrentSound.Source = new Uri(sound.Path, UriKind.Relative);
    }

    private void Sounds_SelectionChanged(object sender, SelectionChangedEventArgs e) {
        var list = ((ListBox) sender);
        var item = (ItemViewModel) list.SelectedItem;
        SelectItem(item);
    }

Also I should point out that the sounds are all resources (build type = Resource). I need them to be because the app needs to discover them dynamically. The paths are all like this, "sounds/foo/bar/sound.wma". Sometimes there is a space in the path, it is url encoded with %20 (this is how the resource manager returns the path, I didn't do that).

The problem is many people, but not all, are saying that the sound auto-repeats. The sounds are very short, only a few seconds, so it's very annoying. I don't understand how this is happening, the MediaElement doesn't even have an auto repeat feature.

Perhaps related, but some have also complained that every now and then the sound does not play. They have to click it again. All I can think of is that there is something wrong with how the sounds are encoded, but they are WMA, and as I said, I encoded them using the 'playback in WP7' settings in expression encoder. How could it be that it works usually but not other times if that were the case, anyway?

I'm at a loss and my app is getting some bad reviews because of this behavior. Help!


Solution

  • The problem with repeating turned out to be needing to do this:

    MediaPlayer.IsRepeating = false;
    

    I think what happened was the user would be in another app that sets this to true, and upon opening my app that value was still true! That has to be a bug, it's totally unexpected. If you look at other sound-playing apps like soundboard apps, there are users complaining in the reviews about the very same thing.. "I wish it wouldn't repeat the sounds..."