In the Silverlight 4 and WP7 programs, you need to use the XNA interface to play the bell sound in the background, instead of relying on a certain xaml page.
Add a reference to Microsoft. Xna. Framework. dll in the project.
After adding a reference, add the following two namespaces at the top of the code file by using:
Using Microsoft. Xna. Framework. Audio;
Using Microsoft. Xna. Framework;
This class only supports WAV files, so only music in WAV format can be used. This is very inconvenient, but WP7's built-in sound is wma. Currently, I have not figured out how it is implemented internally.
Add the WAV audio file to the project.
Then you can use the code to play the sound. The Code is as follows:
1 public class RingPlayerControl 2 { 3 private static readonly Object lockThis = new Object(); 4 private static IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings; 5 6 public static void Play() 7 { 8 lock (lockThis) 9 {10 try11 {12 Stream stream = TitleContainer.OpenStream("Sounds/DOORBELL.WAV");13 SoundEffect effect = SoundEffect.FromStream(stream);14 FrameworkDispatcher.Update();15 effect.Play();16 }17 18 catch (System.Exception ex)19 {20 String strError = ex.ToString();21 }22 23 }24 25 }26 27 }
The TitleContainer. OpenStream method provided by XNA can be used to read the content in the installation folder.
In this way, the sound can be played, but I feel that even the WAV-format ringtones have strict requirements. At first I found several wav ringtones and the Program reported an error: ensure that the specified stream contains valid PCM mono or stereo wave data. it may be that the wav Code cannot be identified on the mobile phone. Later, I found a wav in the mobile app of Windows lele6.1, which is very helpful. Someone has said this here:
Http://forums.create.msdn.com/forums/p/82199/496063.aspx
Mango supports background music, see: http://msdn.microsoft.com/en-us/library/hh202978 (v = VS.92). aspx