BackgroundAudioPlayer doesn't start playing
Asked Answered
B

1

6

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"

Blockhead answered 23/6, 2014 at 5:33 Comment(10)
Maybe you need to take a step back and reevaluate your design; from what I've gathered you're basically trying to play a track and precache the next file while you're still playing (correct me if I'm wrong). That sounds like a pretty easy thing to implement yourself, have you considered doing so?Billi
Sam, problem is not with the design itself but with the WP8. Sample doesn't do any precaching - it's just playing local files through MediaStreamSource/AudioStreamingAgent. Caching next file is just a reason to use MediaStreamSource for playback. It's not the cause itself. Unfortunately, we cannot change design as this is the only approach that fits us.Blockhead
Oh I see; so your basic requirement is to just play local mp3 files? I'm trying to determine what you're doing here (what your core goals are) so I can be of better assistance.Billi
It's worth noting that your 'Sample with problem reproduction' is a VisualStudioVersion = 12.0.30324.0 solution, i.e. it won't open for me in VS2010Rustproof
@Billi my basic requirement is to play local files (mp3) using MediaStreamSource, not just by creating AudioTrack(pathToMp3, title, artist,...).Blockhead
@PaulZahra you are right, it's more than 4 years ago 2010 was released.Blockhead
@Billi We do have. Please read question again. The app has more complex requirements which I simplified just enough to ask the question here.Blockhead
I have read the your question, I just wanted to validate that using MediaStreamSource was an absolute requirement.Billi
I'm having trouble understanding the interactions of your app, but here's something to think about - do you have cross-thread interactions? Perhaps the interaction between BackgroundAudioPlayer and the rest of the app? If so, then this could be a threading bug. Keep in mind, in desktop UI programming, you can only interact with UI objects on the UI thread. I'm not sure how that translates to WP Apps, but I imagine something similar can be found.Sweetbrier
We create AudioTrack in foreground app and set it to BackgroundAudioPlayer.Instance.Track property. Exactly as MSDN describes. There are no other interactions. Bear in mind this is 90% MSDN sample of Background Audio StreamingBlockhead
B
1

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

Bathypelagic answered 2/7, 2014 at 15:29 Comment(1)
Derek, thanks for your answer. However, a) I've seen all these threads, thanks! b) if it was 3rd party app, then maybe we could go with 8.1 preview. Nobody knows release dates and solid business cannot release app that is working on a preview build which will be ready for all users (don't know when). We talked to MS, they also don't say exact dates. c) Document is interesting and actually we have something similar to #3 but implemented using HTTP streaming.Blockhead

© 2022 - 2024 — McMap. All rights reserved.