uwp 中的音频开发
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();
}
}
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 中的音频开发的更多相关文章
- 小强的HTML5移动开发之路(15)——HTML5中的音频
浏览器虽然发展很快,但是浏览器中的标准还是不完善,在HTML4+CSS2+JS的前段开发中让很多程序员头疼的就是浏览器的兼容性问题,音频播放也一样,直到现在,仍然不存在一项网页上播放视频和音频的标准. ...
- UWP开发-在UWP中使用sqlite
原文:UWP开发-在UWP中使用sqlite sqlite是一种轻量级的数据库,对于一些资源紧张又需要数据库的开发非常好用. SQLite 是一个开源的无服务器嵌入式数据库. 这些年来,它已作为面向存 ...
- UWP中实现自定义标题栏
UWP中实现自定义标题栏 0x00 起因 在UWP开发中,有时候我们希望实现自定义标题栏,例如在标题栏中加入搜索框.按钮之类的控件.搜了下资料居然在一个日文网站找到了一篇介绍这个主题的文章: http ...
- 淘宝UWP中的100个为什么
从淘宝UWP第一版发布到现在,已经有十个月了,期间收到了用户各种各样的反馈,感谢这些用户的反馈,指导我们不断的修正.完善应用.但是也有一部分需求或建议,由于资源或技术的限制,目前确实无法做到,只能对广 ...
- 揭秘Windows10 UWP中的httpclient接口[2]
阅读目录: 概述 如何选择 System.Net.Http Windows.Web.Http HTTP的常用功能 修改http头部 设置超时 使用身份验证凭据 使用客户端证书 cookie处理 概述 ...
- UWP中重用C/C++代码时踩过的一些坑
标题中提到的UWP,主要是指用C#来写UWP的主工程,开发过程中可能需要调用C/C++实现的库. 为什么需要调用C/C++的库呢,举个例子,开源库OpenSSL实现了许多加密算法,稳定快速,我们想在应 ...
- Android音频开发之——如何播放一帧音频
本文重点关注如何在Android平台上播放一帧音频数据.阅读本文之前,建议先读一下<Android音频开发(1):基础知识>,因为音频开发过程中,经常要涉及到这些基础知识,掌握了这些重要的 ...
- UWP中使用Composition API实现吸顶(1)
前几天需要在UWP中实现吸顶,就在网上找了一些文章: 吸顶大法 -- UWP中的工具栏吸顶的实现方式之一 在UWP中页面滑动导航栏置顶 发现前人的实现方式大多是控制ListViewBase的Heade ...
- UWP: 在 UWP 中使用 Entity Framework Core 操作 SQLite 数据库
在应用中使用 SQLite 数据库来存储数据是相当常见的.在 UWP 平台中要使用 SQLite,一般会使用 SQLite for Universal Windows Platform 和 SQLit ...
随机推荐
- C语言:2.2.1-4
#include <stdio.h> #define PI 3.1415926 //宏定义末尾没有分别.如果有则成为字符串的一部分 int main() { printf("显示 ...
- Java基础00-异常25
1. 异常 异常 1.1 异常概述 1.2 JVM的默认处理方案 有一行代码报错,下面的代码就不会执行. 1.3 异常处理 如果程序出现了异常,需要我们自己来处理,因为在实际的开发中,不能因为一处的报 ...
- NDT匹配: The Normal Distributions Transform: A New Approach to Laser Scan
介绍 大多数激光匹配算法都是基于点或者线的特征匹配,该论文提出一种2D激光扫描匹配算法,方法类似于占据栅格,将2D平面分为一个个cell,对于每个cell,设定其一个正态分布,表示该网格测量到每个点的 ...
- java并发编程基础——线程池
线程池 由于启动一个线程要与操作系统交互,所以系统启动一个新的线程的成本是比较高的.在这种情况下,使用线程池可以很好的提升性能,特别是程序中涉及创建大量生命周期很短暂的线程时. 与数据库连接池类似,线 ...
- Appium -- adb monkey操作(一)
1.Monkey简介在Android的官方自动化测试领域有一只非常著名的"猴子"叫Monkey,这只"猴子"一旦启动,就会让被测的Android应用程序像猴子一 ...
- 记一次.Net5接入支付宝SDK的小插曲
由于业务需求,在项目里面要接入支付宝的支付功能,于是在github上找到了支付宝的官方sdk:https://hub.fastgit.org/alipay/alipay-easysdk 先说问题: 在 ...
- CreateWindow() -- 创建普通的窗口
(1)函数原型 1 HWND CreateWindow( 2 LPCTSTR lpClassName, //pointer to register class name 3 LPCTSTR lpWin ...
- maven之---资源过滤 在java/main/resourse/*.xml ,*.properties引用maven属性${db.username}
本文主要来源maven实战14.3 为了应对环境的变化,首先使用Maven属性将这个会发生变化的部分提取出来.在上一节的数据库配置中,连接数据库使用的驱动类,URL,用户名和密码都可能发生变化,因此使 ...
- VUE 之_this.da 和 this
作者:张艳涛 日期:2020-07-29 this用在第一层,如果在JS第3二层,要用 _this importfxx(obj) { let _this = this; let inputDOM = ...
- MySQL隔离级别的实现
虽然平时已经很少使用MySQL了,但是数据库作为基本技能仍然不能忘,最近在学习数据库隔离级别,在此写下个人理解以备复习. 大家都知道数据库事务ACID(原子性.一致性.隔离性和持久性)的四个特征,也知 ...