M. Coutinho
M. Coutinho

Reputation: 305

Play Sound Effect Windows Phone

Im trying to play a sound in my silverlight windows phone app (using SDK 7.1 Tools), when a button is pressed, but it seems that it only plays the sound when it finishes the last one.

For example, if I touch repeatly the button, it wont play the sound in the same way.

How can I solve this?

Im using media element in my xaml page

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <MediaElement x:Name="kick" Source="/Sounds/Kick.wav" AutoPlay="False" Visibility="Collapsed"/>
            <Button Content="Button" Height="72" HorizontalAlignment="Left" Margin="165,196,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
        </Grid>

and on code behind i have:

private void button1_Click(object sender, RoutedEventArgs e)
{
    kick.Play();
}

Upvotes: 0

Views: 2592

Answers (1)

M. Coutinho
M. Coutinho

Reputation: 305

OK, If someone has the same problem I found this solution.

1st: Add Reference (Microsofot.Xna.Framework) to your project

2nd: Don't forget to add this to your Page.xaml

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio; 

3rd: Add your sounds to your project, for example, with the path: "Sounds/Sound1.wav"

4th: You can now play the sonds with the following code

PlaySound("Sounds/Sound1.wav");

Upvotes: 1

Related Questions