0

i'm trying to make an application for windows phone 7.1 for schoool. I want to play a sound for each pressed button on my application (just like istantfun button for android) but i have some problem. If i declare on my xaml all the 120 Media Elements my applcation will play only 3/4 sound randomly. I want to make something like this:

private void button1_Click(object sender, RoutedEventArgs e)
    {
        prova.Source = new Uri("/mp3/call.mp3", UriKind.Relative);
        prova.Play();
    }

where prova is a single MediaElement declared on the first page of xaml file. How can i do? Thanks advice

1 Answers1

1

first of all if you want play sound in multi-page app than media element is no good solution. Besides of it's limitation (single sound at a time) and after considering amount of sound effects maybe you should try using XNA as described here: http://www.dotnetscraps.com/dotnetscraps/post/Play-multiple-sound-files-in-Silverlight-for-Windows-Phone-7.aspx

public void PlaySound(string soundFile)
{
    using (var stream = TitleContainer.OpenStream(soundFile))
    {
        var effect = SoundEffect.FromStream(stream);
        FrameworkDispatcher.Update();
        effect.Play();
    }
}

With this solution you don't need any XAML elements and thus you can play it app-wide.

Runaurufu
  • 116
  • 3
  • 3