Search code examples
c#streamingmp3windows-phone

Windows Phone 7: delay in mp3 streaming


I have a problem with streaming of audio on windows phone 7 (nokia lumia 800):

The app is windows phone 7.1, I have tried it on nokia lumia 800 (WP7.8) and lumia 820 (WP8.0)

I put a URL ( http://abc.radiostreaming.dk/ ) into my playlist:

AudioTrack track = new AudioTrack(this.streamURI, "FOO", "BAR", "", null);
BackgroundAudioPlayer.Instance.Track = track;

I subscribe to BackgroundAudioPlayer.Instance.PlayStateChanged with different eventhandlers to change the UI (change button back and forth between "play" and "stop", and update "now playing"-textfield)

When I press play, the UI updates via the eventhandler to show a "buffering" icon, and then change that to "playing" again when BackgroundAudioPlayer.Instance.PlayerState changes to PlayState.Playing.

On a nokia lumia 820 UI and sound works as expected, on lumia 800 BackgroundAudioPlayer.Instance.PlayStateChanged fires (changes to "Playing") and there is a faint tick in the headphones, but then there is a 5-6 second delay before the music starts playing.

The delay is of course annoying (the sound plays almost instantly on the 820), but that is acceptable if I can detect it and update the UI accordingly, that is not working right now using only

BackgroundAudioPlayer.Instance.PlayStateChanged.

Any ideas on other event I can subscribe to, or ways to tweak how fast the sound starts playing (tweaking buffering perhaps? no luck with that so far....)


Solution

  • I have made a workaround: when I get

    BackgroundAudioPlayer.Instance.PlayStateChanged -> PlayState.Playing
    

    I check the BackgroundAudioPlayer.Instance.Position.Milliseconds, if it is 0 the stream is not really playing, so I just recheck every 100ms and then only change the UI from "buffering" to "playing" when BackgroundAudioPlayer.Instance.Position.Milliseconds > 0

    It solves the problem, but is a bit more messy than you would prefer, oh well :)