こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
起動時、ボタン押下時にmp3ファイルを再生したいです。
###試したこと
mp3をリソースに追加、XAMLで配置。
LoadおよびButton_Clickでplay。
###発生している問題・エラーメッセージ
LoadおよびButton_Clickでplayしても音が出ません。
Explorerの単独では再生します。なのでボリュームは問題なし。
Visual StudioでVolume設定が必要でしょうか?
###該当のソースコード
xaml
1<Window x:Class="MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 mc:Ignorable="d" 7 Loaded="Window_Loaded" Unloaded="Window_Unloaded" Topmost="True" 8 WindowState="Maximized" 9 WindowStyle="None" 10 > 11 <Grid> 12 <Grid Width="900" Height="700" Margin="100"> 13 <Grid.RowDefinitions> 14 <RowDefinition Height="50"/> 15 <RowDefinition Height="500*" /> 16 <RowDefinition Height="50"/> 17 <RowDefinition Height="0"/> 18 </Grid.RowDefinitions> 19 <Border Grid.Row="0" > 20 <Image HorizontalAlignment="Left" VerticalAlignment="Center" Height="35" Margin="10,0,0,0"/> 21 </Border> 22 <Image Grid.Row="1" x:Name="Finder" VerticalAlignment="Top" ></Image> 23 24 <Button x:Name="Button" Grid.Row="2" Content="button" FontSize="20" 25 Width="180" Height="50" Click="Button_Click" IsDefault="True"/> 26 <MediaElement Grid.Row="3" x:Name="sound" Volume="1" 27 LoadedBehavior="Manual" 28 Width="100" 29 Height="100" 30 Source="pack://siteoforigin:,,,/Resources/sound.mp3"> 31 </MediaElement> 32 </Grid> 33 </Grid> 34</Window>
C#
1using System; 2using System.ComponentModel; 3using System.Windows; 4using System.Windows.Controls; 5using System.Windows.Media.Imaging; 6 7namespace WPF { 8 public partial class MainWindow : Window { 9 public MainWindow() { 10 InitializeComponent(); 11 } 12 13 private void Window_Loaded(object sender, RoutedEventArgs e) { 14 sound.Play(); 15 } 16 17 private void Button_Click(object sender, RoutedEventArgs e) { 18 sound.Play(); 19 } 20 } 21}
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038
インストールしているバージョン:Community
Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015
です。
よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。