资源描述
播放音乐
添加进入声音时,要将音频时间置零。
音频格式最好是MP3格式的。
页面代码:
<UserControl x:Class="MusicAndMovie.MainPage"
xmlns="
xmlns:x="
xmlns:d="
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="500">
<Canvas x:Name="CanvasOne" Width="500" Height="400">
<MediaElement x:Name="MusicOne" Source="Sound/Start.mp3" AutoPlay="True" ></MediaElement>
<MediaElement x:Name="MusicTwo" Source="Sound/click.mp3" AutoPlay="False"></MediaElement>
<Button Name="btnGuess" Width="105" Height="40" Canvas.Left="324" Canvas.Top="291" Content="You Can Try Me!"
MouseEnter="btnGuess_MouseEnter" MouseLeave="btnGuess_MouseLeave"></Button>
</Canvas>
</UserControl>
后台代码:
using System;
using System.Windows.Controls;
using System.Windows.Input;
namespace MusicAndMovie
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void btnGuess_MouseEnter(object sender, MouseEventArgs e)
{
TimeSpan time=new TimeSpan ();
MusicTwo.Position = time;
MusicTwo.Play();
btnGuess.Content = "You Can Try Me !";
}
private void btnGuess_MouseLeave(object sender, MouseEventArgs e)
{
TimeSpan time = new TimeSpan();
MusicOne.Position = time;
MusicOne.Play();
btnGuess.Content = "Baybay!";
}
}
}
播放视频
注意:设置资源后,将Web重新生成一下。AutoPlay应置为False
页面代码:
<UserControl x:Class="Float.MainPage"
xmlns="
xmlns:x="
xmlns:d="
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<MediaElement Source="TEB4ES_P01_C06_L01.wmv" AutoPlay="False" Width="800" Height="600" Name="mv01" ></MediaElement>
<Button Name="btnStart" Width="50" Height="30" Margin="338,258,12,12" Click="btnStart_Click" MouseEnter="btnStart_MouseEnter" MouseLeave="btnStart_MouseLeave" Content="播放"></Button>
</Grid>
<UserControl.Resources>
<Storyboard x:Name="storyOne">
</Storyboard>
</UserControl.Resources>
</UserControl>
后台代码:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Float
{
public partial class MainPage : UserControl
{
bool isplay = true;
public MainPage()
{
InitializeComponent();
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (isplay)
{
btnStart.Content = "暂停";
mv01.Play();
isplay = false;
}
else
{
btnStart.Content = "播放";
mv01.Pause();
isplay = true;
}
}
private void btnStart_MouseEnter(object sender, MouseEventArgs e)
{
//添加鼠标进入效果、函数
}
private void btnStart_MouseLeave(object sender, MouseEventArgs e)
{
}
}
}
展开阅读全文