Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:54:02+00:00 2026-05-24T20:54:02+00:00

I have built a simple game in WP7 and I am trying to add

  • 0

I have built a simple game in WP7 and I am trying to add background music to it using MediaPlayer. The problem is it just bombs with

{“An unexpected error has occurred.”} System.Exception {System.InvalidOperationException}

Code

try
                {
                    MediaPlayer.Stop();
                    // Timer to run the XNA internals (MediaPlayer is from XNA)
                    DispatcherTimer dt = new DispatcherTimer();
                    dt.Interval = TimeSpan.FromMilliseconds(33);
                    dt.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };
                    dt.Start();

                    Uri pathToFile = new Uri("Audio/music.m4a", UriKind.Relative);
                    Song playingSong = Song.FromUri("Music", pathToFile);
                    MediaPlayer.Play(playingSong);
                }
                catch (Exception e)
                {
                    musicFailed = true;
                    Console.WriteLine("Exception: {0}", e.ToString());
                    MessageBox.Show("Warning, music failed to play however you can still continue to play your game.");
                }
            }

I tried a few tweaks, converting file to mp3, different paths etc. The file is marked for copy always and content type I also tried removing the Dispatcher as dont know what that is for.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:54:03+00:00Added an answer on May 24, 2026 at 8:54 pm

    If you can convert your audio files to WAV format, you can try using the XNA SoundEffect and SoundEffectInstance classes:

    SoundEffect se = SoundEffect.FromStream(isolatedStorageFileStream);
    SoundEffectInstance sei = se.CreateInstance();
    sei.Play();
    

    For this to work, you will need to reference the XNA library (Microsoft.XNA.Framework) and initialize the framework in this way:

    App.xaml:

    <Application>
        <Application.ApplicationLifetimeObjects>
            <local:XNAFrameworkDispatcherService />
            ...
        </Application.ApplicationLifetimeObjects>    
    </Application>
    

    And create this class somewhere in the app namespace (“local” in the previous xaml references this namespace):

    public class XNAFrameworkDispatcherService : IApplicationService
    {
        private DispatcherTimer frameworkDispatcherTimer;
        public XNAFrameworkDispatcherService()
        {
            this.frameworkDispatcherTimer = new DispatcherTimer();
            this.frameworkDispatcherTimer.Interval = TimeSpan.FromTicks(333333);
            this.frameworkDispatcherTimer.Tick += frameworkDispatcherTimer_Tick;
            FrameworkDispatcher.Update();
        }
        void frameworkDispatcherTimer_Tick(object sender, EventArgs e) { FrameworkDispatcher.Update(); }
        void IApplicationService.StartService(ApplicationServiceContext context) { this.frameworkDispatcherTimer.Start(); }
        void IApplicationService.StopService() { this.frameworkDispatcherTimer.Stop(); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just began learning Java programming, I have created a simple game using
Hi I have built a simple WCF application I am using to query data
I have built a very simple blog application using Ruby on Rails. New to
Does Python have a built-in, simple way of encoding/decoding strings using a password? Something
Hey, so I'm trying to build a simple lan game using sockets (not tcpclient
I have built a simple TCP server and need to compare client input with
I have built a simple menu in jQuery http://vanquish.websitewelcome.com/~toberua/ Here is a sample of
I have built a pretty simple REST service in Sinatra, on Rack. It's backed
I have a simple Android application that uses a JAR I have built. When
I have a simple web app built in asp.net webforms c# where and how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.