I'm implementing a game for WP7, and I need that a mp3 file plays in background, while I navigate through some screens. How can I do this? Thanks in advance.
Use background Audio agent for this purpose to play , even when user navigate between pages.
Also you can achieve the continuous playback by 2 ways
1. set the repeat option to play continuously
or
2. start play back again upon receiving the stop message, this can be achieved by putting code for starting playback again in Application Background player state handler upon receiving "PlayState.Stopped" message.
Please refer this link "How to: Play Background Audio for Windows Phone" for more details.
Hm.. what about global MediaPLayer instance?
See this link
Related
I m developing an app which can record audio stream.
I want to know that is it possible to record that audio in background, i,e when the application is in deactivated mode?
I have already tried to do that in many different ways,but its not helping out.
Please suggest me some way to do such...
Thank you.
As mentioned in the comments, it's not possible to record in the background.
Your app must be running in the foreground for it to be able to record audio using the microphone. For an overview of all the audio recording options, please refer to this tutorial on the Nokia Developer Wiki.
Also, an app will not run when the phone is locked - it is suspended. So if your app was recording, it would stop when the phone is locked. You can change this behaviour with IdleDetectionMode.Disabled which means your app keeps running even though the phone is locked.
Haven't implemented it before, but classifying it as a VOIP app could be the way to go:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207046(v=vs.105).aspx
I'm using BackgroundAudioPlayer for my Windows Phone 7 music & video application. After I play some music, I play video using MediaPlayerLauncher, then press Back to return to my app. There whenever I use BackgroundAudioPlayer.Instance. I receive error "The background audio resources are no longer available".
Someone on MSDN suggests using try/catch, but this is not a good idea, and can slow down the app.
Other suggests call BackgroundAudioPlayer.Instance.Close() before launch MediaPlayer. However, when I play music, the agent load .dll again, which takes very much time.
How to fix this ?
If you play a video after your audio the OS will definitely "terminate" your Background Audio Player. From your question it seems this is reproducible 100% of the time which would confirm this. Your only option is to restart the background audio player again after you have called BackgroundAudioPlayer.Instance.Close(), and then played your video. Which as you said will require reloading your player DLL when you start the BAP.
Update following up from comments
If you aren't implementing a streaming audio agent but only an AudioPlayer agent there isn't a process for you to kill anyway. The OS spins up a process as and when it needs to get you to process an action (e.g.: user action, track ended, shutdown).
BackgroundAudioPlayer.Instance.Close() just makes sure that the OS releases those resources cleanly in a scenario such as the OP has.
To restart background audio, just call BackgroundAudioPlayer.Instance.Play() again.
I am trying to capture the current playing track in the Zune music player, in my Background Agent app. Looking at the Unsupported APIs for Background Agents page on MSDN, all of XNA is not supported - which means I can't use XNA's Media.MediaPlayer. Is there any workaround or solution for this?
Nope.
There is currently no way to access anything other than the tracks which you are playing in a BackgroundAudioPlayer agent.
Actually, there is no way to access anything other than THE track (not tracks) that the background audio player is playing. There is no concept of a playlist exposed by the BAP singleton, which apparently is the source for much frustration with this component. You have to resort to IsolatedStorage or some other hack to feed the BAP a playlist.
what I want to achieve is this:
Play background music from the media library
On a certain trigger, fade out the music, play another mp3 file (of various lengths, seconds up to a minute)
After that piece of audio is played, resume previous music from the library
Now I run into these constraints:
In order to access and play music from the user's library, I need to use the MediaPlayer XNA class.
In order to play an arbitrary mp3 file, I need to use either MediaPlayer or MediaElement, but not SoundEffect or SoundEffectInstance
If I play anything using the MediaElement, MediaPlayer stops. It completely loses the audio queue so I would need to play the remaining music which would be ok BUT
MediaPlayer doesn't support seek so I cannot open the previous song and just go the the position before it got paused
So:
I don't want to use SoundEffect or SoundEffectInstance as the audio would have to be wav files.
I can't use just MediaPlayer because if I played the audio there to interrupt the song I wouldn't be able to seek to its previous position
I can't use the combination of MediaPlayer and MediaElement as MediaPlayer stops the MediaPlayer which again prevents me from resuming previous playback
I can't just use MediaElement because it can't play songs from the library
Do you see anything I missed or is really the only option I have to suck it up and use wav files? (There would be many of these downloaded on the fly and it is just plainly inefficient this way!) Any suggestions?
Thanks!
Unfortunately you've hit a limitation of the platform.
In addition to the alternative you've identified you could play the music streamed from an external source through a MediaElement. By using a timer to keep track of how much has played, when resuming the track start that far through the track by including the start point in your request to the streaming server. This does of course mean you need to provide or find a suitable streaming capability. :(
Neither of these are ideal but for now that's the best we have. The background audio facilites coming in Mango may help but until details are announced we can't say for sure.
can't use just MediaPlayer because if I played the audio there to interrupt the song I wouldn't be able to seek to its previous position
You will get mediastatechanged event using MediaPlayer and inthat event you could check the state of the mediaplayer and Pause the Song and then you could also Resume the song
I would like to mute other applications sounds when my application is playing a sound. I know that this is possible in Windows 7 because it allows sound control on a per-application basis.
The specific scenario is my app needs to have its sound play exclusively; if other applications (eg Winamp, Media Player Classic etc) are playing a sound, they should be muted for the duration of the sound played by my application.
I would like to know how it can be done using Delphi? Which library/system call?
I doubt this is easily achieved.
What if the other apps took the same view? Suppose another app decided that it wanted its sound to play and mute all other apps. Which app would win?
On Vista & above you can do this by using CoreAudio/WASAPI & an exclusive mode stream.
Mumble is doing this, you can look at source code.