Playing ringtones for Windows Phone 7

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.