0

I'm using BackgroundAudioPlayer agent for my Windows Phone 7 application. I know that the AudioPlayer class lives in another process (let's call it audio agent process).

I heard that "In theory the process for an Audio Player agent could get started and stopped at any time".

Sometimes, when I press play on my UI, the agent process seems to NOT start, and the agent code doesnot receive any OnUserAction event. And this cause my application to behave wrongly.

I want the agent process to be ready when I want to play music. How to fix this ?

onmyway133
  • 45,645
  • 31
  • 257
  • 263
  • Does the same code sometimes work? Or does it never start? – keyboardP Nov 29 '12 at 13:19
  • @keyboardP the problem sometimes happen. It seems that the agent process takes some time to start. And this cause unexpected behavior. – onmyway133 Nov 29 '12 at 13:29
  • Unless you can reproduce it, I'm not sure what it could be from the info given. Could it be related to this? http://stackoverflow.com/questions/7269070/preinitialize-backgroundaudioplayer-in-wp7 – keyboardP Nov 29 '12 at 13:46
  • @keyboardP the problem sometimes occur when I open my application. The agent seems to not start. But if I call some UserAction (Play, SkipNext, SkipPrevious, ...) after that, it starts – onmyway133 Nov 30 '12 at 04:10
  • What if you force the `Stop` call when the app starts, just to initialize it? – keyboardP Nov 30 '12 at 14:46
  • @keyboardP Sometimes the agent seems to NEVER start, and it cannot receive any UserAction or StateChanged event ! – onmyway133 Dec 01 '12 at 15:24

1 Answers1

0

Maybe you need to start playing audio inside dispatcher? Something like next:

Dispatcher.BeginInvoke( () => { StartAudioOrSoOn(); });

Try to check examples provided by Microsoft for Windows Phone developers:

Windows Phone Samples: learn through code

RredCat
  • 5,259
  • 5
  • 60
  • 100