-1

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

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.

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 :-)

EDIT:

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

}

My XAML Code for the Picture is:

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

XAML Code for MediaSound is:

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

XAML Code for the Button is:

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

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

  • Can you debug (or write debug information to console) in order to find out if the Click Handler is being called? That would help people help you. – meneses.pt May 01 '14 at 09:10
  • It would be difficult to help you unless you post some code. – Cloud9999Strife May 01 '14 at 09:39
  • hi, sorry... wasnt sure if having the code would help :-). Added it now. Would be great if either of you have an idea. No Error comes up, no debugging Window pops open. The sound simply doesnt play on my test device after I changed the background image. – user3577114 May 01 '14 at 11:35
  • I think the tag windows-phone-8 might be wrong here? It should be windows-phone-8.1 ? Your MediaElement has a property Autoplay, this is only available in WP8.1. Are you using 8.1 or 8? – Cloud9999Strife May 01 '14 at 12:07
  • well...I am using the 8.1 SDK but this app is for WP8.0 (though tested on a WP8.1). How would you add the Play function to WP8.0? perhaps thats were the issue is (although, it shouldnt play any sound then in the first place). **Edit** I tried removing the AutoPlay property completely, yet no success. Plus, I am certain that Autoplay is/was available for WP8.0 too (according to some tutorials that are out there) – user3577114 May 01 '14 at 12:16
  • According to http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.autoplay , the minimum supported phone is "Windows Phone 8.1 [Windows Runtime apps only]" – Cloud9999Strife May 01 '14 at 12:44
  • ok, once I am back at my computer at home I will try this - perhaps thats my mistake, that I did not set the image as a Grid.Background but just as a normal Image. (Just wonder why someone gave me a -1 for not showing enough effort... I researched all night to find a solution ;-)) – user3577114 May 01 '14 at 12:45
  • and according to more or less official tutorials like this one http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/Part-3-Writing-your-First-Windows-Phone-8-App it is available for WP8.0 as well. But then again, I dont want to fight about a tag, whether it is wrong or write. I want to figure out why it isnt working the way it should do. Would you have any idea? Again, any help is much appreciated as I have done plenty of research, tried several things and nothing is working. It is probably something simple and I overcomplicate things, but right now I am stuck. – user3577114 May 01 '14 at 12:53

1 Answers1

0

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

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

Community
  • 1
  • 1
Ehz
  • 2,027
  • 1
  • 12
  • 11
  • thanks. but the funny thing is that I ended up with even more issues now. basically, what I did, I put the loading image part asside for a moment and wanted to make sure that at least the buttons work correctly and everyting is setup etc. So I added all the other buttons that were needed and guess what.. nothing worked in the end :-(. Strange thing is that there was no pattern as to why etc. Having 2 Buttons, sound plays fine, having more than 2 Buttons randomly 1 button will work and the others wont. After hours of trying different things to resolve the issue I just gave up... – user3577114 May 02 '14 at 09:50