更改背景图像后声音被禁用 [英] Sound disabled after changing background image

查看:26
本文介绍了更改背景图像后声音被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了更改背景图像后声音被禁用的问题.

I have an issue with sound being disabled after changing a background image.

基本上,我拥有的是 PanoramaItem.在该项目中,我放置了 1 张大图像作为背景图像(可以说是一面旗帜).在那个标志上,我有几个按钮可以在按下时更改按钮图像(在 Blend 中创建的 XAML 代码)并且还会播放声音.(使用 Click 事件处理程序 Sound.Play();)

Basically, what I have is a PanoramaItem. In that Item I have placed 1 big image as the background image (lets say a flag). On that flag I have several buttons that will change the button image on press (XAML Code created in Blend) and will also play a sound. (using Click Event Handler Sound.Play();)

一切正常,只要图像是预加载的(布局-图像在后面,按钮在顶部/前面.

All works fine, as long as the image is preloaded (. Layout-Image is in the back and buttons are on top/front.

但是,我现在还添加了一个按钮,使用户可以使用 PhotoChooserTask 将图像更改为他们自己库中的某些内容.现在的问题是,是的,图像被用户选择的图像替换,但按钮不再播放任何声音.但是,当按下和释放按钮时,按钮图像仍然会发生变化,这意味着按钮仍然处于活动状态/启用状态,但声音被禁用或单击事件处理程序不再工作.

However, I have now also added a button that enables the user to change the image to something from their own library, using the PhotoChooserTask. The problem now is that, yes the image gets replaced by the one the user selects but the buttons are not playing any sound anymore. The Button image still changes though, when pressed and released, which means the button is still active/enabled yet the sound is either disabled or the click even handler is no longer working.

你知道这是为什么吗?昨晚我玩了一整夜,无法弄清楚.

Would you have an idea as to why that is? I played around with it all night last night and couldn't figure it out.

非常感谢任何帮助:-)

Any help is greatly appreciated :-)

这是我用来加载图片的代码:

Here is the code that I am using to load the picture:

void photoChooserTask_Completed(object sender, PhotoResult e)
 {
if (e.TaskResult == TaskResult.OK)
{
     System.Windows.Media.Imaging.BitmapImage bmp = new     System.Windows.Media.Imaging.BitmapImage();
   bmp.SetSource(e.ChosenPhoto);
   BackGroundIMG.Source = bmp;
}

}

我的图片 XAML 代码是:

My XAML Code for the Picture is:

<Image Name="BackGroundIMG" Source="/Assets/Test.jpg" Grid.RowSpan ="3" Grid.ColumnSpan = "3"/>

MediaSound 的 XAML 代码是:

XAML Code for MediaSound is:

<MediaElement x:Name="Theme" Source="/Assets/Theme.wav" Volume="1" Autoplay="False"/>

按钮的 XAML 代码是:

XAML Code for the Button is:

<Button Name="Button1" Click="Button1_Click" Grid.Row="1" Grid.Column ="1"/>

图像和按钮在同一个网格中.在 Layout 下,我将 BackGroundImage 设置为Sent to Back",按钮位于其顶部.

Image and Button are in the same Grid. under Layout I have set the BackGroundImage to "Sent to Back" and the Button is on top of it.

用于播放声音的 C#:

C# for playing Sound:

private void Button1_Click (object sender, RoutedEventargs e)
{Theme.Play();}

同样,当我启动应用程序并按下按钮时声音播放良好,但一旦我更改背景图像就不会播放声音.

So again, the sound plays fine when I start the App and just press the button but no sound will be played once I change the background image.

所以我的猜测是,图片未正确加载,但我不确定如何测试/更改它.

So my guess is, that the picture is not loaded correctly, but I am not sure how to test/change that.

推荐答案

我认为问题不完全在于更改图像,而在于打开 PhotoChooserTask.我怀疑如果您使用任何内置的启动器和选择器,音频也会被切断.http:///msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.tasks(v=vs.105).aspx

I think the issue is not exactly with changing the image but with the opening of the PhotoChooserTask. I suspect if you used any of the built-in launchers and choosers the audio would cut out as well. http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.tasks(v=vs.105).aspx

要使 MediaElement 工作,它必须是可视化树的一部分,否则它将停止播放.当这些选择器任务打开时,它们将离开当前页面.我认为,如果您在 App.Xaml 中使用全局 MediaElement,则可以绕过这种行为.这篇文章有一个创建全局媒体元素的方法:导航到其他页面后继续播放的全局 MediaElement

For a MediaElement to work it has to be part of the visual tree, otherwise it will stop playing. When these chooser tasks open they are navigating away from the current page. I think if you use a global MediaElement in your App.Xaml instead you could get around this behaviour. This post has a method of creating a global media element: Global MediaElement that continues playing after navigating to other page

这篇关于更改背景图像后声音被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆