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至此目录
当前名称:WPF视频音频实现方法解析
分享URL:http://www.csdahua.cn/qtweb/news19/500519.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网