首页 > 其他分享 >uwp 中的音频开发

uwp 中的音频开发

时间:2023-06-06 17:32:16浏览次数:29  
标签:音频 uwp Uri private 开发 new wma currentPlayer AlarmSound

xml code
---------------------------------------------------
<UserControl x:Class="WinTest.HPControl.ReminderTimer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WinTest.HPControl"
             mc:Ignorable="d" Height="158.036" Width="417.35">
    <Grid>
        <Border  BorderBrush="White"  Background="White" CornerRadius="20" >
            <Grid Background="Transparent" Width="300">
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80"></ColumnDefinition>
                    <ColumnDefinition Width="10"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Button Background="Transparent"  Grid.Row="0" Grid.RowSpan="3" Click="Button_Click" >
                    <Image   Source="/images/Alarm.png"  ></Image>
                </Button>
               
                <TextBlock FontFamily="{StaticResource RegularFont}" Foreground="#333333" FontSize="18" Grid.Column="2" Grid.Row="0">时间</TextBlock>
                <TextBlock FontFamily="{StaticResource LightFont}" FontWeight="Light" Foreground="#333333" FontSize="16" Grid.Column="2" Grid.Row="1">时间</TextBlock>
                <TextBlock FontFamily="{StaticResource LightFont}" FontWeight="Light" Foreground="#666666" FontSize="10" Grid.Column="2" Grid.Row="2">时间</TextBlock>
                <StackPanel Grid.Column="2" Grid.Row="3" Orientation="Horizontal">
                    <ToggleButton>toggle switch</ToggleButton>
                    <TextBlock Margin="20,0,0,0">提醒已生效</TextBlock>
                    <Button Click="ReminderTimer_replay">replay</Button>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</UserControl>
 
 
C#  code  后台
------------------------------------------------------------------
 public partial class ReminderTimer : UserControl
    {
        private SoundPlayer player = null;
        private MediaPlayer currentPlayer = null;
        public ReminderTimer()
        {
            InitializeComponent();
            this.Loaded += ReminderTimer_Loaded;
            player = new SoundPlayer();
            this.Unloaded += ReminderTimer_Unloaded;
        }
 
        private void ReminderTimer_Unloaded(object sender, RoutedEventArgs e)
        {
            currentPlayer.Stop();
            currentPlayer.Close();
 
        }
 
        private void ReminderTimer_Loaded(object sender, RoutedEventArgs e)
        {
            initalplayer();
        }
        private void inital()
        {
            string str = System.IO.Directory.GetCurrentDirectory();
            string path = Environment.CurrentDirectory;
            string p = new Uri("ms-appx:///sound/AlarmSound.wma").ToString();
            // string m=  Application.StartupPath;
            //  player.SoundLocation = "/sound/美国往事.wav";//(将播放音乐放在应用程序Debug目录下)
            // player.SoundLocation = "美国往事.wav";
            int index = str.LastIndexOf(@"\bin");
            if (index > 0)
            {
                str = str.Substring(0, index) + @"\sound\AlarmSound.wma";
            }
            player.SoundLocation = str;
            player.Load();
            //音乐播放
            player.Play();
        }
        //ToastAudio Audio;
        private void initalplayer()
        {
            currentPlayer = new MediaPlayer();
 
 
            //Audio = new ToastAudio()
            //{
            //    Loop = true,
            //    Src = new Uri("ms-appx:///HPControls/Assets/AlarmSound.wma")
            //}
 
 
            //"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma"
            // Src = new Uri("ms-appx:///HPControls/Assets/AlarmSound.wma")
            var path = @"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma";
            //Uri audioUri = new Uri("ms-appx:///WinTest/sound/AlarmSound.wma");
            Uri audioUri = new Uri(path);
            
            currentPlayer.Open(audioUri);
            currentPlayer.MediaEnded += CurrentPlayer_MediaEnded;
            currentPlayer.Play();
        }
 
        private void CurrentPlayer_MediaEnded(object sender, EventArgs e)
        {
            var path = @"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma";
            //Uri audioUri = new Uri("ms-appx:///WinTest/sound/AlarmSound.wma");
            Uri audioUri = new Uri(path);
 
            currentPlayer.Open(audioUri);
            currentPlayer.Play();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            currentPlayer.Stop();
        }
 
        private void ReminderTimer_replay(object sender, RoutedEventArgs e)
        {
            currentPlayer.Play();
        }
    }

 

uwp 中的音频开发_Desktop

 

 

 

public partial class ReminderTimer : UserControl    {        private SoundPlayer player = null;        private MediaPlayer currentPlayer = null;        public ReminderTimer()        {            InitializeComponent();            this.Loaded += ReminderTimer_Loaded;            player = new SoundPlayer();            this.Unloaded += ReminderTimer_Unloaded;        }
        private void ReminderTimer_Unloaded(object sender, RoutedEventArgs e)        {            currentPlayer.Stop();            currentPlayer.Close();
        }
        private void ReminderTimer_Loaded(object sender, RoutedEventArgs e)        {            initalplayer();        }        private void inital()        {            string str = System.IO.Directory.GetCurrentDirectory();            string path = Environment.CurrentDirectory;            string p = new Uri("ms-appx:///sound/AlarmSound.wma").ToString();            // string m=  Application.StartupPath;            //  player.SoundLocation = "/sound/美国往事.wav";//(将播放音乐放在应用程序Debug目录下)            // player.SoundLocation = "美国往事.wav";            int index = str.LastIndexOf(@"\bin");            if (index > 0)            {                str = str.Substring(0, index) + @"\sound\AlarmSound.wma";            }            player.SoundLocation = str;            player.Load();            //音乐播放            player.Play();        }        //ToastAudio Audio;        private void initalplayer()        {            currentPlayer = new MediaPlayer();

            //Audio = new ToastAudio()            //{            //    Loop = true,            //    Src = new Uri("ms-appx:///HPControls/Assets/AlarmSound.wma")            //}

            //"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma"            // Src = new Uri("ms-appx:///HPControls/Assets/AlarmSound.wma")            var path = @"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma";            //Uri audioUri = new Uri("ms-appx:///WinTest/sound/AlarmSound.wma");            Uri audioUri = new Uri(path);                        currentPlayer.Open(audioUri);            currentPlayer.MediaEnded += CurrentPlayer_MediaEnded;            currentPlayer.Play();        }
        private void CurrentPlayer_MediaEnded(object sender, EventArgs e)        {            var path = @"C:\Users\bruce\Desktop\UWP\WinTest\sound\AlarmSound.wma";            //Uri audioUri = new Uri("ms-appx:///WinTest/sound/AlarmSound.wma");            Uri audioUri = new Uri(path);
            currentPlayer.Open(audioUri);            currentPlayer.Play();        }
        private void Button_Click(object sender, RoutedEventArgs e)        {
            currentPlayer.Stop();

        }
        private void ReminderTimer_replay(object sender, RoutedEventArgs e)        {            currentPlayer.Play();        }    }


标签:音频,uwp,Uri,private,开发,new,wma,currentPlayer,AlarmSound
From: https://blog.51cto.com/u_4018548/6426509

相关文章

  • uwp 的个人名片
       xmlcode----------------------------------------------------------------------<Pagex:Class="AdaptiveLayout.MainPage"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.......
  • 广州电商直播系统定制开发方案-提升电商业绩的关键利器
    在如今竞争激烈的电商行业,如何有效提升销售转化率和用户参与度是每个电商企业都面临的重要挑战。而广州电商直播系统的开发成为了提升电商业绩的关键利器。接下来,广州名锐讯动系统开发公司将带大家探讨一下广州电商直播系统的开发方案。一、广州电商直播系统需求分析1.用户需求:广......
  • JeeCms低代码开发平台了解及认知以及遇到的问题
    1、jeecms低代码开发平台自带标签,使用的标签延续freemarker标签或基于freemarker标签自定的标签(类似自jsp自定义标签)(1)什么是freemarker标签:FreeMarker标签是一种模板语言,用于在Java应用程序中生成动态Web页面或文本文件。它基于Java模板技术的设计思路并扩展......
  • Flutter音频播放之just_audio
    just_audio的使用just_audio,它是一个用于播放音频的Flutter插件。安装和导入just_audio要使用just_audio库,需要将其添加到项目的pubspec.yaml文件中:dependencies:just_audio:^0.9.34然后运行以下命令以安装该库:flutterpubget要使用just_audio,需要在代码中......
  • 东邻到家小程序|东邻到家系统开发|上门服务系统功能
    家政服务市场鱼龙混杂,价格不透明同时还存在服务时间的问题,为了解决这些问题,一些公司推出了东邻到家小程序,通过在线预约、智能配对、标准化服务等方式,提供更加便捷的家政服务,同时还让服务人员有正规的接单平台,那么东邻到家小程序有哪些功能和优势呢?接下来小编就给大家介绍下。东邻到......
  • 统信UOS系统开发笔记(三):从Qt源码编译安装之编译安装Qt5.12.8
    前言  上一篇,是使用Qt提供的安装包安装的,有些场景需要使用到自己编译的Qt,所以本篇如何在统信UOS系统上编译Qt5.12.8源码。<br>统信UOS系统版本  系统版本:  Qt源码下载  参考博文《获取下载Qt安装包,Qt源码全国网址备忘录(不用注册Qt账户,即可下载各版本Qt安装包和Qt源......
  • CW32-Template CW32F030开发板工程模板
    国产MCUEmbedded-CW32-Board-TemplateEmbedded-CW32-Board-TemplateCW32-Template第三方资源集合CW-TemplateCW32开发者开发板资料CW32-Board开发板资料合集官方提供的案例ExamplesCW32F030_StandardPeripheralLib\ExamplesCW32-48F大学计划板例程EX1流水灯实验......
  • RocketMQ:一个纯java的开源消息中间件--开发测试环境搭建
    一、简介  RocketMQ的前身是Metaq,当 Metaq 3.0发布时,产品名称改为RocketMQ    MetaQ2.x版本由于依赖了alibaba公司内部其他系统,对于公司外部用户使用不够友好,推荐使用3.0版本。   项目地址: https://github.com/alibaba/RocketMQ二、安装RocketMQ   安装Rocket......
  • AI换脸视频换脸流量主小程序开发
    AI换脸视频换脸流量主小程序开发AI转动漫、AI视频换脸、AI绘画、AI换脸。支持多种盈利模式·点数充值,多种点数充值,让用户自由选择。激励视频,接入抖音、微信等流量主广告。多种风格可选,内容丰富,趣味性十足,增加用户使用粘度,男生、女生、文艺、炫酷、唯美、爱情。支持小程序一键上传......
  • 云图说|ModelArts开发环境,让AI开发、探索、教学更简单
    摘要:ModelArts开发环境,以云原生的资源使用和开发工具链的集成,目标为不同类型AI开发、探索、教学用户。本文分享自华为云社区《【云图说】|第280期ModelArts开发环境,让AI开发、探索、教学更简单,提升云化AI开发体验~》,作者:阅识风云。ModelArts开发环境,以云原生的资源使用和开发工......