This project has moved and is read-only. For the latest updates, please go here.

Stop and resume current playing stream when using OS play and pause buttons

Oct 27, 2014 at 2:24 PM
Edited Oct 27, 2014 at 2:39 PM
I don't use the playlist but start a radiostream with a button click. When I go outside the app and pause with the os controls and then resume, the first Item from the playlist starts to play but I want the item which was allready playing before pausing it to start playing again. Any tips?
Oct 29, 2014 at 10:45 AM
If you are using WP7/WP8 background audio, then you will probably want to record the track and position to persistent storage when playback is shut down (for the "case PlayState.Shutdown:" in AudioPlayer.OnPlayStateChanged()?). If you are using something like HlsView.*, then OnNavigatedFrom() is probably a reasonable place to do this. When playback starts, then look to see if there is persisted track/position information before using the defaults.
Nov 5, 2014 at 10:36 PM
I'm using wp8 background audio streaming. The position it not needed because I want the radiostream to stop streaming when pressing the pause button. (which should behave like a stop button) and then re-start buffering and streaming when pressing the play button.

It looks like the stream is still playing in the backgroud when I pause it and I would like it to stop. Could you point me in the right direction? For some reason I can't get it to stop,but only to pause. (Which means it's still using data but is only muted)

I tried BackgroundAudioPlayer.Instance.Stop(); on the pauseButton_Click event..but in the debugging window I can see it's reopening the stream url and then pauses it.

Nov 5, 2014 at 11:00 PM
I think what you might be seeing is the "Stream is not closed" issue. Could you try using HttpConnection? It uses sockets directly, so the Silverlight HttpClient's odd behavior shouldn't get in the way.

Either uncomment HttpConnectionModule in SM.Media.Platform.WP8's TsMediaManagerBuilder (you can comment out HttpClientModule, leaving it will not hurt since the last one registered will win). If you don't want to muck with the SM.Media.Platform.WP8 project, you can get at the Autofac builder like this:
using Autofac;
using SM.Media.Builder;
    _mediaStreamFacade = MediaStreamFacadeSettings.Parameters.Create();

    var builderBase = (BuilderBase)_mediaStreamFacade.Builder;

    var builder = builderBase.ContainerBuilder;

To call "builder.RegisterModule<>()", you will need to add the Autofac NuGet package to that project.
Nov 10, 2014 at 9:55 AM
Hi Henric,

I'm stuck. My programming skills are not good enough I think. Is it possible to send you my app source code by e-mail so you could have a look at it?


Nov 11, 2014 at 3:26 AM
I been meaning to make this a simple-to-use switch for a while. The latest changes add a flag to control if HttpConnection is used.

If you add,
    MediaStreamFacadeSettings.Parameters.UseHttpConnection = true;
to AudioTrackStreamer's constructor (in Libraries\SM.Media.BackgroundAudioStreamingAgent.WP8\AudioTrackStreamer.cs), then you should be using HttpConnection.