从网上下载音频的uwp作业

0.前沿:

    今天我们不节外生枝,只讲核心的需求的解决方案

1. 要求:

    - 能播放在线音频

    - 能下载在线音频到对应操作系统(其实也就windows)用户目录下的音乐文件夹

2. 效果:

项目地址: https://github.com/HallWoodZhang/SimpleMediaPlayer_UWP

    



3. 分析

- 播放在线音频:

    给定url, 然后用微软自带的播放器去播放这个音源,很简单

VideoPlayer.Source = MediaSource.CreateFromUri(new Uri(this.url));

- 下载指定音频

    首先,你需要在项目的功能界面里面选音乐库,不然win10不让你下载的

https://docs.microsoft.com/en-us/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries


    然后你需要利用HTTP协议下载序列化的文件流

https://docs.microsoft.com/en-us/windows/uwp/networking/httpclient


下载样例代码

httpResponse = await httpClient.GetAsync(requestUri);
httpResponse.EnsureSuccessStatusCode();
httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

保存样例代码

StorageFolder testFolder = await StorageFolder.GetFolderFromPathAsync(@"C:\test");
StorageFile sourceFile = await testFolder.GetFileAsync("TestImage.jpg");
StorageFile destinationFile = await KnownFolders.CameraRoll.CreateFileAsync("MyTestImage.jpg");

using (var sourceStream = await sourceFile.OpenReadAsync())
{
    using (var sourceInputStream = sourceStream.GetInputStreamAt(0))
    {
        using (var destinationStream = await destinationFile.OpenAsync(FileAccessMode.ReadWrite))
        {
            using (var destinationOutputStream = destinationStream.GetOutputStreamAt(0))
            {
                await RandomAccessStream.CopyAndCloseAsync(sourceInputStream, destinationStream);
            }
        }
    }
}
剩余的的部分,比如GUI的切换,页面的高斯模糊,并不涉及核心要求,这里就不再讨论了



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值