Cloud Training (Online)




How to save ringtone in Windows Phone using SaveRingtoneTask?

Sometimes , it is might be possible where the user might like a specific audio in an app and wish to save the audio as ringtone provided the audio file meets the ringtone criteria like the type of the file , size of the file and the DRM protection.

How to save ringtone in Windows Phone using SaveRingtoneTask?

The developers can utilize the chooser SaveRingtoneTask to allow the users to save the audio file as ringtone. Just create an instance of the SaveRingtoneTask and set the file name from the app that you wish to save as ringtone . The user will later save the ringtone and can set it as ringtone to different contacts from the People’s hub.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp3.Resources;
using Microsoft.Phone.Tasks;

namespace PhoneApp3
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            RingToneSave();
        }
        // SK - function to save the ringtone
        private void RingToneSave()
        {
            SaveRingtoneTask ringtoneTask = new SaveRingtoneTask();
            ringtoneTask.Completed += saveRingtoneChooser_Completed;
            ringtoneTask.Source = new Uri("appdata:/ringtone1.wma");
            ringtoneTask.DisplayName = "Thuppaki Theme";
            ringtoneTask.Show();
        }

        void saveRingtoneChooser_Completed(object sender, TaskEventArgs e)
        {
                if(  e.TaskResult == TaskResult.OK)
                {
                    MessageBox.Show("Ringtone successfully saved");
                }                 

         }

        }
}

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.