扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
WPF视频音频的播放方法可以通过一段代码来帮助我们实现。这里将会为大家带来详细的实现方法,希望对又需要的朋友有所帮助。#t#
专注于为中小企业提供网站制作、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业昌宁免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了超过千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
WPF视频音频之Window1.xaml代码
WPF视频音频之Window1.xaml.cs代码
- using System;
- using System.Collections.
Generic;- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace WpfApplication1
- {
- /// < summary>
- /// Window1.xaml 的交互逻辑
- /// < /summary>
- public partial class Window1
: Window- {
- public Window1()
- {
- InitializeComponent();
- }
- private void button1_Click(object
sender, RoutedEventArgs e)- {
- //用MediaPlayer类进行播放
- MediaPlayer player = new MediaPlayer();
- player.Open(new Uri(Environment.
CurrentDirectory + "\\music.mp3",
UriKind.Relative));- VideoDrawing aVideoDrawing =
new VideoDrawing();- aVideoDrawing.Rect = new
Rect(0, 0, 100, 100);- aVideoDrawing.Player = player;
- player.Play();
- }
- private void button2_Click(object
sender, RoutedEventArgs e)- {
- //用MediaElement控件进行播放
- McMediaElement.Source = new
Uri(Environment.CurrentDirectory
+ "\\music.mp3");- McMediaElement.Play();
- }
- }
- }
其中Environment.CurrentDirectory表示和项目生成的exe同一目录,请将WPF视频音频文件copy至此目录
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流