Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BackgroundAudioPlayer doesn't start playing

Windows Phone 8 app. We're using AudioStreamingAgent/Mp3MediaStreamSource to play MP3 files which could be cached locally or loaded from web.

When file is downloaded we are still using AudioStreamingAgent /Mp3MediaStreamSource to ensure we will be able to precache next file while playing current. Yes, we could use just WP8 built-in player for cached files, but we will not be able to precache next file in this case.

Problem: After several tracks, BackgroundAudioPlayer doesn't start playing anymore.

  1. AudioStreamingAgent.OnBeginStreaming is executed
  2. Сode to create MediaStreamSource is executed
  3. AudioStreamer.SetSource method is executed with new MediaStreamSource instance
  4. PlayStateChanged is fired in background process with PlayState.TrackReady and player.Play() is called in this case.

After all, I see the track is shown in UVC, but it's in state "Paused". Pressing "Play" in UVC calls OnUserAction in background which calls player.Play(). Nothing changes.

Picture of "stuck state"

Sample with problem reproduction, VS 2012 (sample is based on Background Audio Streamer Sample)

Steps to reproduce with sample code:

  1. Install app
  2. Press button "Preload tracks". It copies mp3 files from XAP to IsolatedStorage.
  3. Press "Track 1" button. After track starts playing, press button "Track 2". Then, after track 2 starts playing, press button "Track 3".
  4. Keep doing step 3 until after pressing "Track *" button track doesn't start playing.
  5. Last track selected will be shown as an active track both in UVC and above progress bar on the page (see picture)
  6. Pressing other track buttons in most cases doesn't make any difference.

The problem is reproduced both on device and on emulator, both on WP8 and WP8.1 developer preview.

Update: Running out of memory is not the case. Reproducing the problem using sample code and looking at the backgroundlog.xml file shows that sample uses only 6 Mb out of 20 Mb allowed Last column on this picture is "Memory usage|Max allowed memory usage"

like image 503
Alex Sorokoletov Avatar asked Jun 23 '14 05:06

Alex Sorokoletov


1 Answers

In my experience with this, my suggestion would be to port and start working with WPA8.1 where the limitations with playing background audio go away.

In developing a music player app for WP and trying to cache music while using a mediastreamsource, I finally came to the conclusion that it might not be possible. It seems that you have a set amount of time or some other variable before the OS stomps on any tasks or background type work being done.

I wrote this up for a MS evangelist: https://drive.google.com/file/d/0By_e5C-QWr9Ka3RmbVBlWVF3R1E/edit?usp=sharing

Here are some other SO's I favored when trying to solve this:

BackgroundAudioPlayer is 'Playing' but not calling GetSampleAsync()

WP7 background audio resources are no longer available

HttpWebRequest from AudioPlayerAgent

AudioPlayerAgent, timer and webservice

WP7 Mp3MediaStreamSource demo not working

like image 93
Derek Beattie Avatar answered Oct 04 '22 01:10

Derek Beattie