Murtaza Fazal's Blog

Murtaza Fazal's Blog
Murtaza Fazal's Blog

Wednesday, June 15, 2011

Alarm in Windows Phone 7.1 (Mango)

How often we want to create an application which could generate Alarm in the background and play it on the specified time? Once me and my brother were investigating this same task on iPhone and what we found was... the audio won't play for more then 40 seconds . Implementing the same thing on Windows Phone 7.1 (Mango) is piece of cake :) Just few lines of code and you are done.

I'll demonstrate how to write a simple program which plays any audio which you want :)


  1. Create a new Project
  2. Select Target Framework as 7.1
  3. In you Main.xaml.cs , include the library  "Microsoft.Phone.Scheduler".
  4. I've placed the audio file on the root , if you want you can create a folder as audio and place your file there. Then you should navigate as per your need. 
  5. Now write the following code 
    • Alarm myAlarm = new Alarm("mmfAlarmTest");   
      • // You need to specify a name for the alarm
    • myAlarm.BeginTime = DateTime.Now.AddMinutes(1);  
      • // I would like it to play after 1 minute of execution
    • myAlarm .Sound = new Uri("/toss-the-feathers.mp3",UriKind.RelativeOrAbsolute); 
      • // Remember my audio file is on the root directory?
    • ScheduledActionService.Remove("mmfAlarmTest");  
      • // Remove if there exist a similar alarm
    • ScheduledActionService.Add(myAlarm);   
      • // Register your alarm


And that's it !!! . Test it out and enjoy the fun ;) Using this, you can generate an application which sets alarm through your application

No comments:

Post a Comment