• WPF音乐播放器 零基础4个小时左右


    前言:winfrom转wpf用久的熟手说得最多的是,转回去做winfrom难。。当时不明白。。做一个就知道了。

    WPF音乐播放器

    入口主程序

    1. FontFamily="Microsoft YaHei" FontSize="12" FontWeight="ExtraLight"
    2. 居中显示
    3. WindowStartupLocation="CenterScreen" ResizeMode="NoResize"
    4. Title="音娱乐行音乐播放器" Height="600" Width="1010"
    1. 无边框
    2. "1"/>
    1. StackPanel 块 Orientation="Horizontal" 水平显示 HorizontalAlignment="Center" 居中
    2. "Horizontal" HorizontalAlignment="Center">
    3. "28" Height="28" CornerRadius="10">
    4. "../Assets/Images/Logo.png" Stretch="UniformToFill"
    5. Viewport="-0.3,-0.3,1.6,1.6"
    6. Opacity="0.5"/>
    7. "" FontFamily="{StaticResource FF}" VerticalAlignment="Center" HorizontalAlignment="Left"
    8. FontSize="20" Foreground="ForestGreen" Height="19" Width="18" Margin="-14,0,0,0">
    9. "5" Color="ForestGreen" ShadowDepth="0" Opacity="0.5"/>
    10. "音娱乐行播放器" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="Orange"
    11. FontSize="13" FontWeight="Bold"/>

    **************

    菜单栏目

    1. "1">
    2. "首页" Tag="" Style="{StaticResource MenuButtonStyle}" IsChecked="True"/>
    3. "有声动态谱" Tag="" Style="{StaticResource MenuButtonStyle}" IsChecked="True"/>
    4. "精品歌单" Tag="" Style="{StaticResource MenuButtonStyle}"/>
    5. "歌手推荐" Tag="" Style="{StaticResource MenuButtonStyle}"/>
    6. "单曲排行" Tag="" Style="{StaticResource MenuButtonStyle}"/>
    7. "3" Margin="40,0,10,0">
    8. "流行" Style="{StaticResource ClassButtonStyle}"/>
    9. "民谣" Style="{StaticResource ClassButtonStyle}"/>
    10. "电子" Style="{StaticResource ClassButtonStyle}"/>
    11. "舞曲" Style="{StaticResource ClassButtonStyle}"/>
    12. "说唱" Style="{StaticResource ClassButtonStyle}"/>
    13. "轻音乐" Style="{StaticResource ClassButtonStyle}"/>
    14. "爵士" Style="{StaticResource ClassButtonStyle}"/>
    15. "乡村" Style="{StaticResource ClassButtonStyle}"/>
    16. "更多" Style="{StaticResource ClassButtonStyle}"/>
    17. "{Binding SList}" Margin="40,0,10,0">
    18. "{Binding Header}" Tag="{Binding Icon}"
    19. Style="{StaticResource SheetButtonStyle}"/>

    样式控件

    1. MenuButtonStyle 样式
    2. //
    3. // 控件触发器 样式触发器
    4. MenuLabelStyle 样式
    5. ClassButtonStyle 样式

    后台绑定数据

    指定关系

     DataContext = new MainViewModel();

    右侧内容

    1. "1">
    2. "50"/>
    3. "28" Width="180" HorizontalAlignment="Left"
    4. Style="{StaticResource SearchTextBoxStyle}"
    5. VerticalContentAlignment="Center" Margin="30,0"/>
    6. "1" VerticalScrollBarVisibility="Hidden">
    7. "30,0">
    8. fistpage 页面

    爬虫

    数据绑定

    1. "热门专辑" VerticalAlignment="Center" FontWeight="Bold"
    2. Foreground="#555"/>
    3. "1" BorderThickness="0" Background="Transparent"
    4. ItemsSource="{Binding AlbumList}" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
    5. "Horizontal"/> 水平显示
    6. 模板
    7. 数据模板
    8. "auto"/>
    9. "100" Height="100" CornerRadius="5" >
    10. "{Binding Cover}"/>
    11. "5"
    12. ShadowDepth="0" Color="Gray" Opacity="0.5"/>

    数据列表绑定

    数据细节处理

    ps:学wpf没有个大屏是个阻力哈哈哈

    播放控制器

    1. DataContext.PlayDownloadCommand,RelativeSource
    2. 播放命令指向信息

    指向信息帮助类 有点深入自己看

    1. public class Command<T> : ICommand
    2. {
    3. public event EventHandler? CanExecuteChanged;
    4. public bool CanExecute(object? parameter)
    5. {
    6. return true;
    7. }
    8. public void Execute(object? parameter)
    9. {
    10. dynamic param = parameter;
    11. DoExecute?.Invoke(param);
    12. }
    13. public Action DoExecute { get; set; }
    14. public Command(Action action)
    15. {
    16. DoExecute = action;
    17. }
    18. }
    19. public class Command : Command<object>
    20. {
    21. public Command(Action action) : base(obj => action?.Invoke()) { }
    22. }

    其他类似

    小经验

    分界线 深吭来了

    1. public async void Play(SongModel song)
    2. {
    3. var options = new LaunchOptions { Headless = true };
    4. // 这里有个深坑哈 先要跑一边 下载运行环境 后 注释掉
    5. // await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
    6. //注意 两个using
    7. using (var browser = await Puppeteer.LaunchAsync(options))
    8. using (var page = await browser.NewPageAsync())
    9. {
    10. await page.GoToAsync(song.Url);
    11. //请求之后 就是用语法 有就获取src
    12. var jsSelectAllAnchors = @"Array.from(document.querySellectorAll('audio')).map(a=>a.src);";
    13. var urls=await page.EvaluateExpressionAsync<string[]>(jsSelectAllAnchors);
    14. if (urls != null&&urls.Length>0)
    15. {
    16. wc.DownloadFile(urls[0],"./songs/"+song.SongName+".mp3");
    17. }
    18. }
    19. }

    遇到的问题 jsSelectAllAnchors 这里面的命令哪里来的 写错了一个单词 找了有点久 

    细节UI 播放控制台

    双击

    跑起来了 

    简单的播放 可以下载播放 下载延迟很耗时间 

    小编表示 wpf 界面代码写起来 这还是有点底子 ,写起来 比vue webfrom react 都麻烦=.=。。。。。

    .net几行代码音乐API各排行榜 热搜 入库-CSDN博客

    ABP.Next系列02 搭个API框架要多久 项目下载 运行 -Fstyle_【abp vnext】下载并运行web api项目详细教程文档-CSDN博客

  • 相关阅读:
    多线程_synchronized锁与Lock锁
    12. Spring源码篇之创建Bean逻辑doCreateBean
    番茄工作法,为何总不奏效
    如何在java中将日期时间设置为一天结束
    北京筑龙&京东安全:为采购与招标平台筑起“防火墙”
    Unity包围盒
    死锁的常见例子及 Python 模拟
    数商云S2B2C商城积分商城功能如何实现家用电器企业营销价值最大化?
    CSDN课程推荐:《ARMv8/ARMv9架构学习》系列课程上线-56节18小时
    01-10-Hadoop-HA-概述
  • 原文地址:https://blog.csdn.net/cao919/article/details/139399302