How to play sounds periodically? - windows-phone-7

With the new WP 7.1 they added Background Agent to play sound files from within your application, and TaskScheduler Agent to run tasks periodically.
However:
I want to play sounds periodically even if my application is closed.
TaskScheduler does not allow to play audio via XNA sound effects, BackgroundAudioPlayer or MediaElement (http://msdn.microsoft.com/en-us/library/hh202962%28v=vs.92%29.aspx)
TaskScheduler runs for a specific time with a FIXED interval of 30 seconds. I need to play a sound every hour on the hour.
Alarms can have a sound set to them, but there is no way to customize that dialog to not show and not need snooze or dismiss functionality.

There's no way to play sounds from a Background/Live Agent as there is no way to implement the required UI prompts that would be needed to satisfy the marketplace certification requirements around other music which may be playing on the device at the time.
In theory you could create the functionality you are after with an hour long track that is mostly silent which you play via a background audio player. In reality though this would likely be a big drain on the battery and would prevent the user playing other music.
If you can explain why you want to do this we may be able to make alternative suggestions.
Also note that the length of time a scheduled agent can run for is a MAXIMUM of 15 seconds every 30 minutes (plus or minus 10 minutes).

Is there now a possibility to play the sound on the setting timer even if we close the application ?

Related

Background Task in Windows phone is not working

I am Working on Background task in Windows phone application but it is not calling .When do launch for test it is working but in real scenario app is not calling background services.
Do you use ScheduledActionService.LaunchForTest? This function is not supposed to work on a real phone. You have to deal with the fact that instead of running every 1-2 minutes your background task will be launched once every 30 minutes or so as stated in Constraints For Periodic Agents section.
If everything is fine in your simulator, you have to cross your fingers and keep waiting for a half of hour or so just to test that you are actually launched. Yes, it's a pain to debug, but we have no other official way.
You may also try adjusting local time on device. Sometimes going half an hour into the future helps trigger background agent immediately.

Windows phone 8: Live tile updates in the emulator but not when downloaded from the maket

I have made an app with live tile for windows phone 8. The tile is programmed to refresh every 30 seconds. When the run the app in the emulator or when I deploy the app in my cell (Lumia 920) the tile works fine. But surprisingly when I downloaded the same app from the market and run it on the same device the tile doesn't update.
I did quite a bit of research on this problem and found that a similar problem is observed by many other people which can be found here.
Kindly tell me what is going wrong.
Extra Info : I have tried resizing the tile, pin and unpin the tile and hard reset. I have also tried changing the refresh period (initially the refresh period was 5 seconds). I have also checked that the background task is allowed for the app.
Thanks,
Apurva Pathak
Background agents have certain limitations, as listed below.
Background tasks can minimally be run every 30 minutes. There is a debug-only API to run them more regularly, but this is not available for released apps.
Some low power devices do not support background agents
Background tasks are limited by number on each device and can be enabled or disabled from application settings.
They do not work when power saver mode is activated.
As Mahantesh correctly pointed out your tiles work when you deploy the application because the ScheduledActionService.LaunchForTest() is allowed to run for a 60 seconds period for debugging and testing purposes ONLY.
Therefore this method cannot be called and it wont work with a time limit less than 30 minutes if the application is published to the market and users download it from there.

WP7 background audio resources are no longer available

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.

Permanent background task in WP7

Looking into developing an app for WP7 that requires continous monitoring GPS position. From what I can read from some searching there are certain limits to WP7 background tasks. Only scheduled for execution every 30 minutes, run for no more than 25 seconds, etc.
I would like to know how to bypass these limitations to permanently run a background task capable of monitoring GPS in real-time. (Think of Google Latitude for instance.)
You can't do that unless your app is actually running on the phone.
No background task can be permanent on WP7.

is it possible to make an alarm or countdown timer app?

I'm a complete noob when it comes to WP7. From what I know of it, in WP7 you wouldn't be able to make an alarm clock app. As in, start app, set alarm for an hour from now, close app, app launches and rings alarm after an hour is up.
Is this not possible in WP7? Or is there some way of doing it that I'm not aware of? I have seen a workaround for a stopwatch using tombstoning, but that doesn't seem like it would work here.
With Windows Phone 7 [for 3rd party developers] it's not possible to write an application that runs in the background on the phone. (This was a deliberate decision with regards to maintaining performance and battery life - not a limitation of the OS which is fully multi-tasking.)
If you really want the user to be notified of something at a specific time, regardless of whether your application is running you'll need to have this monitored from a process on an external server and then send a [toast] notification to the user at the appropriate time.
Learn more about push notifications at http://msdn.microsoft.com/en-us/library/ff402537(VS.92).aspx

Resources