0
我在project.shared的资产中添加了声音,并且在XAML页面中添加了MediaElement
。如何从windows资产中播放声音通用应用程序
我想在点击图像时播放声音。
这是我的代码,但它没有奏效。
</Grid>
<GridView VerticalAlignment="Bottom" Margin="-10,-10,10,10" Height="260" Grid.RowSpan="2">
<StackPanel Orientation="Vertical">
<Image Source="/Assets/Animals/cat.png" Height="200" Width="200" HorizontalAlignment="Center" Tapped="Image_Tapped"/>
<TextBlock Text="Cat" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30"/>
</StackPanel>
</GridView>
<MediaElement Name="AudioPlayer" HorizontalAlignment="Left" Height="100" Margin="297,290,0,0" Grid.Row="1" VerticalAlignment="Top" Width="100" Visibility="Collapsed" Volume="1"/>
</Grid>
,这是我的事件处理程序
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
cat.play();
}
cat.play();'中的'cat'是什么?它没有在XAML中声明。 – kennyzx
你也应该处理''MediaFailed'事件](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.mediafailed.aspx) MediaElement'。 –