MediaElement 自动重复剪辑,有时无法播放

发布于 2024-10-23 23:44:29 字数 961 浏览 2 评论 0原文

我有一个应用程序可以播放一些简短的声音剪辑。要播放它们,我只需将源设置为新的剪辑路径,该路径是我使用 WP7 设置通过 Expression Encoder 编码的 WMA。甚至不值得共享代码——有一个事件处理程序。在其中,我将 ME.Source 属性设置为新的 Uri。它已设置为自动播放,就这样!这里:

    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);
    }

我还应该指出,声音都是资源(构建类型=资源)。我需要它们,因为应用程序需要动态发现它们。路径都是这样的,“sounds/foo/bar/sound.wma”。有时路径中会有空格,它是用%20进行url编码的(这是资源管理器返回路径的方式,我没有这样做)。

问题是很多人(但不是所有人)都说声音会自动重复。声音很短,只有几秒钟,所以很烦人。我不明白这是怎么发生的,MediaElement 甚至没有自动重复功能。

也许相关,但有些人也抱怨声音时不时地不播放。他们必须再次点击它。我能想到的是声音的编码方式有问题,但它们是 WMA,正如我所说,我使用表达式编码器中的“在 WP7 中播放”设置对它们进行编码。如果是这样的话,为什么它通常有效,但其他时候却不起作用呢?

我不知所措,并且由于这种行为,我的应用程序收到了一些不好的评论。帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰雪之触 2024-10-30 23:44:29

“有一个事件处理程序”,但你没有说是什么?在某些情况下,该事件可能会反复触发或根本不触发。您的代码可能存在逻辑错误,您无法分离现有处理程序,然后添加另一个处理程序。随着使用的进展,您最终会发现单个事件由多个处理程序处理。

编辑

选择更改事件因触发频率超出我们的预期而臭名昭著。我建议您添加一些去抖代码来记录最后选择的项目以及多久之前的信息。如果下一个选定的项目与上一个选定的项目相同,并且是在不到一秒之前发生的,则吞掉该事件而不执行任何其他操作。

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

隱形的亼 2024-10-30 23:44:29

听起来您可能正在尝试播放声音效果 - 在这种情况下,您最好使用 XNA SoundEffect 机制

,例如http://www.japf.fr/2010/ 08/sound-effect-in-wp7-sl-application/

SoundEffect 仅适用于 WAV 文件 (PCM) - 但我已在多个应用程序和脚本中使用它,包括嵌入内容文件和下载文件(例如 翻译ironruby 脚本)。

XNA 类在 SL 中运行良好,允许同时播放多种音效。

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.

裂开嘴轻声笑有多痛 2024-10-30 23:44:29

重复的问题原来是需要这样做:

MediaPlayer.IsRepeating = false;

我认为发生的情况是用户将在另一个应用程序中将其设置为 true,并且在打开我的应用程序时该值仍然为 true!这一定是一个错误,完全出乎意料。如果您查看其他声音播放应用程序(例如音板应用程序),就会发现有用户在评论中抱怨同样的事情......“我希望它不会重复声音......”

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文