BackgroundAudioTask.MyBackgroundAudioTask.CreatePlaybackList C# (CSharp) Method

CreatePlaybackList() private method

Create a playback list from the list of songs received from the foreground app.
private CreatePlaybackList ( IEnumerable songs ) : void
songs IEnumerable
return void
        void CreatePlaybackList(IEnumerable<SoundCloudTrack> songs)
        {
            // Make a new list and enable looping
            playbackList = new MediaPlaybackList();
            playbackList.AutoRepeatEnabled = true;

            // Add playback items to the list
            foreach (var song in songs)
            {
                if (!string.IsNullOrEmpty(song.stream_url))
                {
                    var source = MediaSource.CreateFromUri(new Uri(song.stream_url.ToString()));
                    source.CustomProperties[TrackIdKey] = song.stream_url.ToString();
                    source.CustomProperties[TitleKey] = song.title;
                    source.CustomProperties[AlbumArtKey] = song.AlbumArtUri;
                    playbackList.Items.Add(new MediaPlaybackItem(source));

                }
            }

            // Don't auto start
            BackgroundMediaPlayer.Current.AutoPlay = false;

            // Assign the list to the player
            BackgroundMediaPlayer.Current.Source = playbackList;

            // Add handler for future playlist item changes
            playbackList.CurrentItemChanged += PlaybackList_CurrentItemChanged;
        }