This is a migrated thread and some comments may be shown as answers.

system beep sound in an xaml file

2 Answers 173 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Meenu
Top achievements
Rank 1
Meenu asked on 20 Aug 2013, 03:54 AM
how can I write code for  playing  system beep sound in an xaml file?

I tried Console.beep() But not working

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2013, 01:00 PM
Hi Meenu,

Console.beep() plays the sound of a beep through the console speaker alone. Apart from this in SilverLight you have a plethora of sound capabilities; one of which is using the MediaElement control. So, you could add one of those to your page as shown below.

XAML:
<MediaElement x:Name="beeper"></MediaElement>

C#:
private void AssignBeep()
{
  Uri beepUri = new Uri("Project;component/beep.mp3", UriKind.RelativeOrAbsolute);
  StreamResourceInfo streamInfo = Application.GetResourceStream(beepUri);
  this.beeper.SetSource(streamInfo.Stream);
  this.beeper.AutoPlay = false;
}
 
private void PlayBeep()
{
  this.beeper.Position = new TimeSpan(0,0,0,0);
  this.beeper.Volume = 1;
  this.beeper.Play();
}

Also you can try the SilverSynth.

Thanks,
Shinu.
0
Meenu
Top achievements
Rank 1
answered on 21 Aug 2013, 06:20 AM
Yes...Done..>Working perfect....Thank u so much.....

I added mp3 file build action to resource
Tags
General Discussions
Asked by
Meenu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Meenu
Top achievements
Rank 1
Share this question
or