質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

1回答

2152閲覧

起動時、ボタン押下時にmp3ファイルを再生したいです。

cancat

総合スコア313

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

0グッド

0クリップ

投稿2016/12/19 02:09

編集2016/12/19 02:10

こんにちは。
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

です。
よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0


投稿2020/01/22 08:21

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問