예제 #1
0
        }   // Download

        private async Task DownLoadFromAs(string inputURL, string filename, string albumcover = "")
        {
            StorageFolder MyDownloadFolder;

            // 定位 folder
            try
            {
                MyDownloadFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(App.MyDownLoadFolder);
            }
            catch (Exception)
            {
                MyDownloadFolder = await DownloadsFolder.CreateFolderAsync("Music", CreationCollisionOption.GenerateUniqueName);

                StorageApplicationPermissions.FutureAccessList.AddOrReplace(App.MyDownLoadFolder, MyDownloadFolder);
            }

            // check if exists music file
            try
            {
                StorageFile destinationFile = await MyDownloadFolder.CreateFileAsync(filename, CreationCollisionOption.FailIfExists);

                if (destinationFile != null)
                {
                    if (PlayArea.Height >= DefaultHeight)
                    {
                        TextBlockStatus.Text = "0%";
                        DownloadBar.Value    = 0;
                        await DownloadBoard.Fade(value : 1.0f, duration : 500, delay : 0, easingType : EasingType.Default).StartAsync();
                    }

                    Uri source = new Uri(inputURL);

                    BackgroundDownloader downloader = new BackgroundDownloader();
                    DownloadOperation    download   = downloader.CreateDownload(source, destinationFile);

                    Progress <DownloadOperation> progress = new Progress <DownloadOperation>(x => ProgressChanged(download));
                    cancellationToken = new CancellationTokenSource();

                    await download.StartAsync().AsTask(cancellationToken.Token, progress);

                    if (DownloadBoard.Opacity == 1.0)
                    {
                        await DownloadBoard.Fade(value : 0.0f, duration : 1000, delay : 1000, easingType : EasingType.Default).StartAsync();
                    }
                }
            }
            catch (Exception)
            {
                // music exist
                FlyoutBase.ShowAttachedFlyout(DownLoadButton);
            }
        }
예제 #2
0
        async void PrepareSourse()
        {
            while (MusicRes == "shit")
            {
            }                               //not get resourse
            StorageFolder MyDownloadFolder;

            // 定位 folder
            try
            {
                MyDownloadFolder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(App.MyDownLoadFolder);
            }
            catch (Exception)
            {
                MyDownloadFolder = await DownloadsFolder.CreateFolderAsync("Music", CreationCollisionOption.GenerateUniqueName);

                StorageApplicationPermissions.FutureAccessList.AddOrReplace(App.MyDownLoadFolder, MyDownloadFolder);
            }

            // try to open exist file
            try
            {
                StorageFile music = await MyDownloadFolder.GetFileAsync(SongPLayingName.Text + MusicRes.Substring(0, 4));

                var mediaSource = MediaSource.CreateFromStorageFile(music);
                App.Musicplayer.Source = mediaSource;

                mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
            }

            // not exist, download it
            catch (Exception)
            {
                StorageFile destinationFile = await MyDownloadFolder.CreateFileAsync(SongPLayingName.Text + MusicRes.Substring(0, 4), CreationCollisionOption.FailIfExists);

                var downloader        = new BackgroundDownloader();
                var downloadOperation = downloader.CreateDownload(new Uri(MusicRes.Substring(4)), destinationFile);
                await downloadOperation.StartAsync().AsTask();

                var mediaSource = MediaSource.CreateFromStorageFile(destinationFile);
                App.Musicplayer.Source = mediaSource;

                mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
            }
        }