4

When I am using the BackgroundAudioPlayer in my Windows Phone 7 application, it takes a lot of time to load the first time I want to play a song. Is there any way of preinitializing the BackgroundAudioPlayer before playing the first track, so that when I start playing, it starts right along? I have googled it, but no luck. I am just using BackgroundAudioPlayer.Instance when I e.g. want to play, pause, stop etc an audiotrack. Is there something other i could do to fix this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
kgrevehagen
  • 514
  • 6
  • 20
  • terminology pick: There are no such things as pre-initialization, re-initialization, etc., there is just "initialization". – Sebastian Mach Sep 01 '11 at 13:32
  • I know, but I wanted to put an emphasis on the fact that I want to initialize it before it gets automatically initialized, which is too late. As I have understood, it initializes when needed, right? How can I do this without calling stop, pause etc? – kgrevehagen Sep 02 '11 at 08:16
  • still picking: How about "explicitly initializing"? Pardon though that I can't help on the question. – Sebastian Mach Sep 02 '11 at 08:33

2 Answers2

3

You could just call BackgroundAudioPlayer.Instance.Stop(); in your App constructor and then discard the first occurance of UserAction.Stop in the OnUserAction method in your implementation of AudioPlayerAgent

mariusgreve
  • 2,621
  • 6
  • 23
  • 31
  • I´ve tried that. Using BackgroundAudioPlayer.Instance.Stop(), it seemed to load 13 of the 18 assemblies, so that was a good improvement. But I would still like to load the 5 remaining before clicking play. – kgrevehagen Sep 01 '11 at 13:13
  • Is it the assemblies loading that cause the problem? If so you could use Assembly.Load() to pre-load them into your app. – Rob Sep 01 '11 at 22:09
  • That didn´t seem to work either. The printline I would like to "bump up" looks like this 'Background Task' (Managed): Loaded 'mscorlib.dll'. The same assembly gets loaded in the UI Task, so how can I explicitly load assemblies that run on a Background task? – kgrevehagen Sep 02 '11 at 09:03
  • @greve what do do mean by the first occurence? What if user use your app to play music, then quit, then come back to your app ? – onmyway133 Nov 30 '12 at 03:00
0

This might be looking at this from a simple angle, but could you not call play and then instantly pause it until you are ready to play?? I'm not hugely familiar with the control but looking here:

http://msdn.microsoft.com/en-us/library/microsoft.phone.backgroundaudio.backgroundaudioplayer_members(v=vs.92).aspx

Upfront you could possibly check BufferingProgress and PlayerState to check when the track is ready to play, and then pause until you're ready to continue.

It's a bit brute force but may work. Worth a try?

Rob
  • 1,687
  • 3
  • 22
  • 34
  • Going to try some of the if checks you recommended to boost it some more. Thanks! More, and other non-brute-force methods are highly appreciated! – kgrevehagen Sep 01 '11 at 13:14