I'm working on app for online radio and use Microsoft background media sample as a start point. I've set sources to URIs for my online radio, but when I begin to change channels in runtime they play from the same point as first time. I think audio caches somehow. So how can I clear cache or start to play selected channel from actual time versus first time it was launched?
Asked
Active
Viewed 992 times
2 Answers
1
It's simple you can manipulate with Media player only through MediaPlaybackList class so let's say that you want to switch to previous track and you want to remove cache of current track than you should use method SkipToPrevious with playbackList.CurrentItem.Source.Reset();
so it can looks like this
/// <summary>
/// Skip track and update UVC via SMTC
/// </summary>
private void SkipToPrevious()
{
smtc.PlaybackStatus = MediaPlaybackStatus.Changing;
playbackList.CurrentItem.Source.Reset();
playbackList.MovePrevious();
}

Shoxik
- 119
- 1
- 7
-
It's look like previously was no such method) – Eugen Kotov Mar 09 '16 at 19:31
0
If you set the playbacklist = null in the MyBackgroundAudioTask.cs and then recreate the playbacklist it clears the cache and starts streaming live. It's probably a clumbsy solution but it does seem to work.
UpdatePlaylistMessageExtra UpdatePlaylistMessageExtra;
if (MessageService.TryParseMessage(e.Data, out UpdatePlaylistMessageExtra))
{
if (playbackList != null)
{
playbackList = null;
CreatePlaybackList(UpdatePlaylistMessageExtra.Songs); //Recreate to start from start and not cached stream
Debug.WriteLine("Playbacklist rebinded in BG");
BackgroundMediaPlayer.Current.AutoPlay = true;
}
return;
}

Joost
- 1
- 1