新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
WPF視頻音頻實現(xiàn)方法解析
WPF視頻音頻的播放方法可以通過一段代碼來幫助我們實現(xiàn)。這里將會為大家?guī)碓敿毜膶崿F(xiàn)方法,希望對又需要的朋友有所幫助。#t#

專注于為中小企業(yè)提供網站制作、網站設計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)昌寧免費做網站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯(lián)網行業(yè)人才,有力地推動了超過千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網站建設實現(xiàn)規(guī)模擴充和轉變。
WPF視頻音頻之Window1.xaml代碼
- < Window x:Class="WpfApplica
tion1.Window1" - xmlns="http://schemas.
microsoft.com/winfx/2006
/xaml/presentation" - xmlns:x="http://schemas.
microsoft.com/winfx/2006/xaml" - Title="Window1" Height="300"
Width="300"> - < Grid>
- < Button Height="23" Margin=
"12,12,0,0" Name="button1"
VerticalAlignment="Top" Click=
"button1_Click" Horizontal
Alignment="Left" Width="74">
Button< /Button> - < Button Height="23" Horizontal
Alignment="Right" Margin="0,12,54,0"
Name="button2" VerticalAlignment="Top"
Width="75" Click="button2_Click">
Button< /Button> - < MediaElement Name="McMediaElement"
LoadedBehavior="Manual"/> - < /Grid>
- < /Window>
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視頻音頻實現(xiàn)方法解析
網站路徑:http://www.fisionsoft.com.cn/article/cdecpcd.html


咨詢
建站咨詢
