/// <summary>
        /// Downloads the song in the background if it's not already available offline.
        /// </summary>
        /// <param name="track"></param>
        public async Task SubmitDownload(MusicItem track)
        {
            await BeforeDownload(track);

            try {
                var maybeLocalUri = await PhoneLocalLibrary.Instance.LocalUriIfExists(track);

                if (maybeLocalUri == null)
                {
                    // For Subsonic, the response may be transcoded audio, in which case the
                    // path to the track, which has the original file extension as stored on
                    // the server, may be incorrect (example: response is transcoded to .mp3,
                    // path is .flac).

                    // TODO: Ensure that the file is stored locally with the correct extension,
                    // that is, find out whether the response is transcoded.
                    var destination = LocalLibrary.AbsolutePathTo(track);
                    var downloadUri = MusicProvider.DownloadUriFor(track);
                    // Only downloads tracks that are stored as MP3s, because this app does not support other local file formats.
                    if (destination.EndsWith("mp3"))
                    {
                        var downloadable = new Downloadable(downloadUri, destination);
                        if (LoadTransfersCount() < 3)
                        {
                            AddTransfer(downloadUri, destination);
                        }
                        else
                        {
                            // add the download to persistent storage from which it will be taken
                            // later when there are fewer concurrent downloads
                            DownloadDataContext.Add(downloadable);
                        }
                    }
                }
            } catch (PathTooLongException) {
                // Thrown if track.Path is about over 190 characters long, but I'm not sure what
                // the limit is and I don't want to be too defensive with this so I catch and
                // suppress the exception when it occurs.

                // The exception says "The specified path, file name, or both are too long.
                // The fully qualified file name must be less than 260 characters, and the
                // directory name must be less than 248 characters.", however, I don't know
                // the length of the fully qualified path name, so 190 chars is an estimate.
                AddMessage("Download of " + track.Name + " failed. The path is too long: " + track.Path);
            }
        }
        public async Task SubmitDownloads(IEnumerable <MusicItem> tracks)
        {
            await BeforeDownload(tracks);

            try {
                var remoteTracks = await tracks.FilterAsync(async track => await PhoneLocalLibrary.Instance.LocalUriIfExists(track) == null);

                var downloadables = remoteTracks
                                    .Select(track => new Downloadable(MusicProvider.DownloadUriFor(track), LocalLibrary.AbsolutePathTo(track)))
                                    .Where(d => d.Destination.EndsWith("mp3"))
                                    .ToList();
                var transfers  = LoadTransfersCount();
                var queueables = (transfers < 3 ? downloadables.Skip(3) : downloadables).ToList();
                if (transfers < 3)
                {
                    foreach (var dl in downloadables.Take(3).ToList())
                    {
                        AddTransfer(dl.Source, dl.Destination);
                    }
                }
                if (queueables.Count > 0)
                {
                    // add the download to persistent storage from which it will be taken
                    // later when there are fewer concurrent downloads
                    DownloadDataContext.AddAll(queueables);
                }
            } catch (PathTooLongException) {
                // Thrown if track.Path is about over 190 characters long, but I'm not sure what
                // the limit is and I don't want to be too defensive with this so I catch and
                // suppress the exception when it occurs.

                // The exception says "The specified path, file name, or both are too long.
                // The fully qualified file name must be less than 260 characters, and the
                // directory name must be less than 248 characters.", however, I don't know
                // the length of the fully qualified path name, so 190 chars is an estimate.
                AddMessage("Unable to submit all tracks for download. A file path was too long.");
            }
        }