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 7760205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:49:15+00:00 2026-06-01T13:49:15+00:00

I have an XNA arcade game which runs over Silverlight environment. The game has

  • 0

I have an XNA arcade game which runs over Silverlight environment. The game has a few sound clips which are played in random order as background music.

As stated in http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.songcollection.aspx, a developer cannot have full control over Media Player. Particularly, developers cannot create their song collections or add songs to the playback queue. There is a recommendation to play songs one at a time by calling MediaPlayer.Play().

That’s exactly what I’m doing but I experience a performance flaw each time when another song starts playing. The game hangs on for a moment when I call MediaPlayer.Play() despite all sound clips are loaded during game initialization, not in runtime. This happens only on some devices (e.g. HTC Mozart). In contrast, if I disable game sounds and play the same clips in phone’s music player while running the game, there are no performance issues during song changes. I also don’t experience performance problems if we play the clips using SoundEffect class. However, I’m strongly willing to use MediaPlayer for background sound purposes due to 2 reasons:
– SoundEffect doesn’t issue notification when playback is completed
– SoundEffect doesn’t seem to work with .mp3 files, and using .wav files is very expensive

I’ve also run profiling tests which confirmed that the poor performance time frame starts in a few milliseconds after MediaPlayer.Play() and continues during about 0,4 seconds. During this time my game doesn’t execute any heavy-weight operations, just regular game timer’s Update() function.

Here is my code snippets:

public void PlayBackgroundMusic(Song song)
{
    if ((!(App.Current as App).AppModel.SoundDisabled) && (song != null))
    {
        if (MediaPlayer.State != MediaState.Stopped)
        {
            StopBackgroundMusic();
        }
        MediaPlayer.Play(song);
    }
}

public void StopBackgroundMusic()
{
    MediaPlayer.Stop();
}

and the handler:

private void OnMediaStateChanged(object sender, EventArgs e)
{
    if (MediaPlayer.State != MediaState.Playing)
    {
        if (!AppModel.SoundDisabled)
        {
            int index = soundRandomizer.Next(0, sounds.Length - 1);
            PlayBackgroundMusic(sounds[index]);
        }
    }
}

Are there any suggestions?

  • 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-06-01T13:49:16+00:00Added an answer on June 1, 2026 at 1:49 pm

    After all, I found a solution which I’m satisfied with. It eliminates jiggling almost completely. Its idea is to use every MediaPlayer API in a separate thread obtained from thread pool. I’m not aware how it fixes the problem but this really works for me:

    public void PlayBackgroundMusic(Song song)
    {
        if ((!(App.Current as App).AppModel.SoundDisabled) && (song != null))
        {
            if (MediaPlayer.State != MediaState.Stopped)
            {
                StopBackgroundMusic();
            }
    
            ThreadPool.QueueUserWorkItem((o) =>
            {
                MediaPlayer.Play(song);
            }
        }
    }
    
    public void StopBackgroundMusic()
    {
        ThreadPool.QueueUserWorkItem((o) =>
        {
            MediaPlayer.Stop();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a simple xna game that i want to port that to silverlight,
I have a game in XNA which needs to do network calls. In the
I have dabbled in the Microsoft XNA game development framework which seems quite good
i'm building a wp7 application for a game using silverlight & XNA i have
I have XNA game and it contains these classes public partial class Bird :
I have a WP7 XNA game that needs to save the state whenever the
i have a problem with the stopping of a windows phone xna game. i
I'm working with xna in C# and in my game I will have a
XNA doesn't have any methods which support circle drawing. Normally when I had to
We have an existing PC game that uses C# and the XNA Framework. We

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.