开发者

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' setti开发者_运维知识库ngs 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!


"there's and event handler" but you don't say of what? It could be that event firing over and over or not at all in some cases. Potentially your code has a logical errors where you have failed to detach an existing handler and then added another. As usage progresses you end up with a single event being handled by multiple handlers.

Edit

The Selection changed event is notorious for firing more frequently than we'd like. I suggest you add some debounce code that makes record of the last item selected and how long ago. If the next selected item is the same as the last one and it was say less than a second ago then swallow the event without doing anything else.


It sounds like you might be trying to play Sound Effects - in which case you might be better off using the XNA SoundEffect mechanism

e.g. http://www.japf.fr/2010/08/sound-effect-in-wp7-sl-application/

SoundEffect only works for WAV files (PCM) - but I've used it in several apps and scripts including embedded content files and downloaded files (e.g. translation and ironruby scripts).

The XNA class works well within SL and allows multiple sound effects to be played at the same time.


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..."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜