How to use the save ringtone task for Windows Phone 8

May 10, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1

Use the save ringtone task to enable users to save an audio file to the system ringtones list. This task launches the Ringtones application, where the user saves the ringtone and can optionally set it as their default ringtone. Once the audio file is added to the list, the user can set it as the ringtone for individual contacts in the Contacts application.

By using Choosers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone 8.

Ringtone audio files must meet the following requirements.

  • Files must be of type M4R, MP3, or WMA.

  • Files must be less than 30 MB in size.

  • Files must not have digital rights management (DRM) protection.

To use the save ringtone task

  1. Add the following statement to your code.

    using Microsoft.Phone.Tasks;
    
  2. Declare the task object. It must have page scope, so declare it in your page before the constructor.

    SaveRingtoneTask saveRingtoneChooser;
    
  3. Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.

    saveRingtoneChooser = new SaveRingtoneTask();
    saveRingtoneChooser.Completed += new EventHandler<TaskEventArgs>(saveRingtoneChooser_Completed);
    
  4. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

    To test this code, you need to add an audio file to your application and name it myTone.wma. You can look for sample ringtones in C:\ProgramData\Microsoft\Windows\Ringtones, or search your computer for any short file with a .wma extension.

    
    
    
    saveRingtoneChooser.Source = new Uri("appdata:/myTone.wma");
    //saveRingtoneChooser.Source = new Uri("isostore:/myTone.wma"); 
    
    saveRingtoneChooser.DisplayName = "My custom ringtone";
    
    saveRingtoneChooser.Show();
    
    
    
    
    
    
    
    NoteNote:

    Use appdata: for audio files that are part of the application project. They are bundled into the XAP file and stored in the installation directory of the application. Use isostore: for audio files that are stored in isolated storage.

  5. Add the code for the completed event handler to your page. This code runs after the user completes the task. You can check to see whether the ringtone was saved successfully.

    void saveRingtoneChooser_Completed(object sender, TaskEventArgs e)
    {
        switch (e.TaskResult)
        {
            //Logic for when the ringtone was saved successfully
            case TaskResult.OK:
                MessageBox.Show("Ringtone saved.");
                break;
    
            //Logic for when the task was cancelled by the user
            case TaskResult.Cancel:
                MessageBox.Show("Save cancelled.");
                break;
    
            //Logic for when the ringtone could not be saved
            case TaskResult.None:
                MessageBox.Show("Ringtone could not be saved.");
                break;
        }
    }
    

Show:
© 2014 Microsoft