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;
FrameworkDispatcher.Update();if (MediaPlayer.GameHasControl){canPlay = true;}else{if (MessageBox.Show(“Is it ok to stop currently playingmusic 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.Stop();mediaDuckSound.Source = new Uri(soundFile, UriKind.Relative);
mediaDuckSound.Position = System.TimeSpan.FromSeconds(0);mediaDuckSound.Volume = 1;mediaDuckSound.Play();
ShowBuyNow();}}
where shud i add dis code?
ReplyDeleteYou Have to Add This Code Before Playing Any Sound ,Song or Media File.
ReplyDelete