Silverlight for Windows Phone 7でMediaElement
コントロールで問題が発生しました。私の目標は、ユーザーがボタンを押したときに2つのトーンを再生することです。私が思いついたこれを行う方法は、各トーンのためにMediaElement
を持つことです。 (おそらくより良い方法はありますか?)SilverlightのMediaElementでの問題
<phone:PhoneApplicationPage
x:Class="MediaElementTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<StackPanel x:Name="LayoutRoot" Background="Transparent">
<MediaElement
x:Name="firstTone"
MediaEnded="firstTone_MediaEnded"
Source="{Binding FirstTone}" />
<MediaElement
x:Name="secondTone"
Source="{Binding SecondTone}" />
<Button Content="Play" Click="Button_Click" />
</StackPanel>
</phone:PhoneApplicationPage>
コードビハインド:
public partial class MainPage : PhoneApplicationPage
{
public Uri FirstTone
{
get
{
return new Uri("A.mp3", UriKind.Relative);
}
}
public Uri SecondTone
{
get
{
return new Uri("B.mp3", UriKind.Relative);
}
}
public MainPage()
{
InitializeComponent();
LayoutRoot.DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
firstTone.Stop();
secondTone.Stop();
firstTone.Play();
}
private void firstTone_MediaEnded(object sender, RoutedEventArgs e)
{
secondTone.Play();
}
}
私はボタンをクリックして
は、何の音が再生されません。どうしてこれなの?私は間違って何をしていますか?
再生する2つのトーンは、実行時まで認識されません。 (私がすべての可能な組み合わせをあらかじめ作っていたのであれば、それは大量のファイルになるだろう。私はむしろプログラムでそれをやっているだろう) –
ああ、OK。誰も同じ提案をしないように私は私の答えを残します。 – MusiGenesis
あなたのウリスに何か問題があると思います。私は、動作するコードサンプルをオンラインで見つけて、それを徐々に修正することをお勧めします。 – MusiGenesis