Search code examples
c#windows-10background-audiouwp

UWP: clear audio stream cache


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?


Solution

  • 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();
    
            }