DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Playing sounds in Windows Phone 7 applications

Playing sounds in Windows Phone 7 applications

Jevgeni Tšaikin user avatar by
Jevgeni Tšaikin
·
Nov. 25, 11 · Mobile Zone · Interview
Like (0)
Save
Tweet
9.72K Views

Join the DZone community and get the full member experience.

Join For Free

In this short tutorial I will show how to play sounds in Windows Phone 7 Silverlight applications. You will be surprised that for playing sounds in Silverlight application you will need to add a XNA Framework reference to your project.

eugenedotnet sounds in windows phone 7 applications

1. Adding reference

First of all you need to add XNA Framework reference to your project. To play sounds in Silverlight applications we are going to use Microsoft.XNA.Framework library.

adding xna framework reference

2. Adding namespaces

Next you need to add two XNA Framework references to your code. You need to add it to a class which is going to be used for playing sounds.

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

3. Creating a method

Finally, we need to created a method for playing sounds within a class. I have used the following code:


private void PlaySound(string path)
{
    if (!string.IsNullOrEmpty(path))
    {
        using (var stream = TitleContainer.OpenStream(path))
        {
            if (stream != null)
            {
                var effect = SoundEffect.FromStream(stream);
                FrameworkDispatcher.Update();
                effect.Play();
            }
        }
    }
}

4. Using method

I have used the following code to test my SoundController class:

SoundController sc = new SoundController();
sc.PlaySound(@"Sounds\show.wav");

Source: http://www.eugenedotnet.com/2010/10/w13-playing-sounds-in-windows-phone-7-applications/
application Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Everything I Needed to Know About Observability, I Learned from ‘Bewitched’
  • Kafka Fail-Over Using Quarkus Reactive Messaging
  • 6 Best Books to Learn Multithreading and Concurrency in Java
  • How To Deploy Apache Kafka With Kubernetes

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo