1
votes

I'm currenly writing an app where I need to use custom sound for toast notifications (which is sent from cloud). MSDN states that the audio clip must be stored in the app's installation directory or local storage folder. So how is this done?

I tried the CopyToIsolatedStorage() code sample from How to play background audio for Windows Phone. It fetches the audio clip correctly but when the toast should be shown the device won't play any audio or even show the toast which indicates that it can't find the audio clip correctly. In the app, I have a method which shows contents of the push notification when the app is in foreground. From there I can see that the toast notification is sent and received correctly with toast.mp3 sound tag. So the problem must be in the app but I can't figure out what I did wrong.

Tl;dr version: I want to change toast notification sound, my device is running WP8 with Update 3 and I have a 5 sec long mp3. I can't figure out how and where I should put the audio clip.

2
It's really hard to say without a few more details. Where did you put the audio file? How did you refer to it in code?WiredPrairie
I followed the "How to play backround audio for Windows Phone" tutorial, clip is in Audio dir with Build action-Content and Copy to Output Directory-Copy always properties. I tried firing up a toast from background agent and setting up sound with SetProperty(toast, "Sound", new Uri("toast.mp3", UriKind.RelativeOrAbsolute)); but it throws FileNotFoundException. So the system cannot find the audio clip automatically (filename parsed from push notification) nor manually (SetPropety).pasik
If they're in the Audio directory, you'll need to include that in the path new Uri(@"Audio\toast.mp3", UriKind.RelativeOrAbsolute)WiredPrairie
In my case the toast is fired up from push notification which has <wp:Sound>toast.mp3</wp:Sound> tag and when the app is in background, the system handles push and toast notifications. The manual handling part was only a test. I checked Using custom sounds in toasts on Windows Phone 8 Update 3 but the information there is quite minimal...pasik
It still looks like the path is wrong as you've specified it. I don't believe it will search the folders for the file.WiredPrairie

2 Answers

2
votes

I dont think you need to copy the sound to isolated storage, just put it in your main project and set it as content. Then in your Push just reference it.

   <wp:Sound>toast.mp3</wp:Sound>

Or if it is in the Assets folder in your project do

   <wp:Sound>Assets/toast.mp3</wp:Sound>

Note: This only works for Windows Phone 8 Update 3 and later, works fine for all Windows Phone 8.1.

1
votes

So the problem was that I blindly assumed one can reference to the audio clip with just <wp:Sound>toast.mp3</wp:Sound> or new Uri("toast.mp3", UriKind.RelativeOrAbsolute), as in the MSDN tutorial, when the file is copied to the root of the isolated storage but this isn't the case. You'll have to include the directory where the clip is in your project to the path, in my case Audio\. Thaks goes to WiredPrairie for pointing this out.

So to wrap things up: Copy the audio clip which you want to use to the isolated storage with CopyToIsolatedStorage() from How to play background audio for Windows Phone and follow the instructions in Using custom sounds in toasts on Windows Phone 8 Update 3 . And remember to include the directory structure to the path of the clip or put the clip in the root of your project.