Question

I trying to play a ringtone for the purpose of alert user when the notification coming. What i wanna to achieve is the ringtone can be play by user and it not a default ringtone.

I successfully to create a listbox and ringtone inside the listbox can be play in the foreground. But when running in background, the default ringtone will alert first and the ringtone play by user will not display. This is what the problem I faced.

An exception found: An exception of type 'System.IO.EndOfStreamException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary

How to stop the default ringtone so i can play the ringtone selected by user in the background?

Any help and suggestion will be appreciated. Thank you.

scheduleTaskAgent.cs

 var stream = TitleContainer.OpenStream("Sound/" + Ringtone);
 // I using isolatedstorage to store the ringtone name and shared to scheduleTaskAgent.cs

 var effect = SoundEffect.FromStream(stream);
 FrameworkDispatcher.Update();
 effect.Play();

 ToastHelper.ShowToast("Monitor:", "You have " + read2 + " Invoice!!", null);
 testVibrateControl.Start(TimeSpan.FromSeconds(3));
 testVibrateControl.Stop();
Was it helpful?

Solution

For the standard OS notification, you are limited to the system sound - you cannot change it and you cannot disable it. However, if the alert is used internally, you might want to take a look at the ToastPrompt control in the Coding4Fun Toolkit - once it is displayed, play the sound.

Also, your playback code should look like this:

SoundEffectInstance currentSI;
using (var stream = TitleContainer.OpenStream("PATH"))
{
    var effect = SoundEffect.FromStream(stream);
    currentSI = effect.CreateInstance();
    FrameworkDispatcher.Update();
    currentSI.Play();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top