Subscribe For Free Updates!

We'll not spam mate! We promise.

May 7, 2012

handle currently playing background music in Windows Phone 7

In this Post i show you handle background music in windows Phone 7. This is an Important thing if you don't care about it (handle Already Playing music) then you cannot published you apps on Market Place.

Yalla App Publishing Requirement is that when ever an already play music file in Background and your app also have some musics sounds then Yor app should Prompt user to stop already  playing music or not . OR you can Just Prompt like "BACKGROUND SOUND IS STOP".

When the user is already playing music on the phone when the application is launched, the application must not pause, resume, or stop the active music in the phone MediaQueue by calling the Microsoft.Xna.Framework.Media.MediaPlayer class.
The application needs to prompt the user for consent to adjust the volume or stop the music that is currently playing in the Zune queue.

Expected Result by MARKET PLACE

Test Process Required:
1. Play audio and/or music media.
2. Launch the application.
3. The application must not pause, resume, or stop the active music on the device.
4. If the application plays its own background music, the application must prompt for user
consent to stop playing or to adjust the currently playing background music.

Using MediaPlayer.GameHasControl to fix the issue

 This is very simple to address by using MediaPlayer.GamehasControl which is part of Microsoft.Xna.Framework.dll with namespace Microsoft.Xna.Framework.Media. It will return false if there are some background music currently being played and you must prompt the user for the permission to stop the background music and play your own sound.

private void PlaySound(string soundFile)
    bool canPlay = false;

    if (MediaPlayer.GameHasControl)
        canPlay = true;
        if (MessageBox.Show(“Is it ok to stop currently playing
music and play our duck caller sound?”, “Can play duck caller?”,
MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            canPlay = true;

    if (canPlay)
        btnPlay.Visibility = System.Windows.Visibility.Collapsed;
        btnPause.Visibility = System.Windows.Visibility.Visible;

        _updatingMediaTimeline = true;
        mediaDuckSound.Source = new Uri(soundFile, UriKind.Relative);

        mediaDuckSound.Position = System.TimeSpan.FromSeconds(0);
        mediaDuckSound.Volume = 1;



Plese Feel Free to Socializer This Post


  1. where shud i add dis code?

  2. You Have to Add This Code Before Playing Any Sound ,Song or Media File.

  3. Looking for the Ultimate Dating Website? Create an account and find your perfect date.

  4. Quantum Binary Signals

    Professional trading signals sent to your mobile phone every day.

    Start following our signals NOW & earn up to 270% per day.


Become a Fan

visual studio learn