Random geekery since 2005.

Husband, father, programmer, speaker, writer, blogger, podcaster, collector, traveler, golfer.

31 Days of Mango | Day #20: Creating Ringtones

Written in

by

Day20-RingtonesDay19-AddingTiltEffectsDay18-ExpressionBlendSampleDataDay17-WindowsAzureDay16-IsolatedStorageExplorer

This article is Day #20 in a series called 31 Days of Mango, and was written by guest author Jerrel Blankenship.  (Yes, I realize the remarkable similarities between our names.)  Jerrel can be reached on Twitter at @thejerrel, and you can find his book, Pro Agile .NET Development with Scrum on Amazon.

Today, we are going to talk about ringtones. With the Mango update of Windows Phone, you as a developer have the ability to write applications that can save a user customized ringtone to their device, for later use. This ability is another way to give the user a chance to have a more customized experience on their phone.

Criteria for audio file

Before you can save a ringtone to the phone, there are some stipulations on the audio file that you need to know.

The audio file must meet the following criteria:

  • It can only be in the WMA or MP3 format
  • It can be no larger than 1MB
  • It be unlocked (DRM free)
  • It can be no longer than approximately 40 seconds

SaveRingtoneTask Chooser method

To save a ringtone from your application to the system, you need to use the Chooser API. The Chooser is an API that allows the caller the ability to launch system applications from their own application. Examples of this include the ability to launch the Contacts app to get information about a person, the Bing Maps application to find directions to a location, and launch the Ringtones application. The Ringtones application is an application that allows you to save a ringtone audio file to the ringtones list in the system. The Chooser task you need to call to launch the Ringtones application is called SaveRingtoneTask.

Creating a custom ringtone application

To better understand this and how to use this task, lets build our own ringtone application that takes an audio file from the app and saves it to the system ringtone list.

image_thumb1

To call the SaveRingtoneTask Chooser, you simply need to instantiate a new instance of this chooser and define a delegate that will be ran once the user is complete with the Ringtones application. The sample below displays the application pictured above. To reference this Chooser task, you need to make sure you included the Microsoft.Phone.Task using.

using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace CustomRingtonesExample
{
    public partial class MainPage : PhoneApplicationPage
    {
        private readonly SaveRingtoneTask _customRingtone;
        
        public MainPage()
        {
            InitializeComponent();
            _customRingtone = new SaveRingtoneTask();
            _customRingtone.Completed += customRingtone_Completed;
        }

        private void customRingtone_Completed(object sender, TaskEventArgs e)
        {
            MessageBox.Show(@"You are back from the Ringtones application. Reference e.TaskResult, in your code, 
            if you want to see if the save was successful.");
        }

        private void SaveButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            _customRingtone.Source = new Uri("appdata:/Audio/ExampleRingtone.wma");
            _customRingtone.DisplayName = "Example Custom Ringtone";
            _customRingtone.Show();
        }
    }
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Things to take note of:

  • You need to define a Completed event handler that will run once the user has completed the task. This method is a great place to check to see what the user did in the task and act accordingly.
  • To call the application, you just need to call the Show() method on the chooser.
  • You can access audio files from data that is part of the application (appdata:) as well as from isolated storage (isostore:).

Summary

To wrap up things for today, custom ringtones give the user a chance to have a more personalized experience with their new Window Phone. By calling the SaveRingtonTask, you can provide a gateway for the user to be able to add this level of customization to their phone.

Have fun coding!

To download a working version of the Windows Phone application covered in this article, click the Download Code button below.

download

Tomorrow, Parag Joshi will be covering a new technology available to Windows Phone developers that has been in very high demand: sockets.  See you then!

toolsbutton

Tags

8 responses to “31 Days of Mango | Day #20: Creating Ringtones”

  1. […] Der Originalartikel befindet sich hier: Day #20: Creating Ringtones. […]

  2. […] No trackbacks yet. « 31 Days of Mango | Day #20: Creating Ringtones […]

  3. […] Read original post by Jerrel Blankenship at BlankenBlog […]

  4. […] Windows Phone Emulator ToolsWhat I Learned In WP7 – Issue 17HTC announced two new Windows Phones31 Days of Mango | Day #20: Creating Ringtones *{margin:0; padding:0;} ul{ list-style:none;} #socialbuttonnav {width:90%; […]

  5. […] 31 Days of Mango | Day #20: Creating Ringtones […]

  6. Tuan Doan Avatar

    hi Jeff,
    Do you know how to get name of ringtone when user finish Chooser?
    For example: I use your sample file “ExampleRingtone.wma”, then I save it as ringtone with name “Jeff” at the Ringtone application page. So how can I get “Jeff” value?

  7. […] Esta es una traduccion de Day 20: Creating Ringtones, puedes encontrarlo aquí en su versión origin… […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

%d bloggers like this: