Thursday, 15 January 2015

c# - How to play a sound in WPF -


I'm a novice C # programmer and I'm having trouble playing music in the game using my WPF (Windows) VS 2008. This is a web app do I think that myMediaElementExample variable is empty when executing it in the Play method ExpenseReportPage.xaml.cs file Is used for

This program is created now, but after running it, it encounters an exception to myMediaElementExample.Play (); The line exception says:

  WpfApplication1.vhost.exe [9 48] generated an uncontrolled Win32 exception.  

Can any of you suggest me what else to try? I have included only the code related to this problem:

ExpenseReportPage.xaml.cs file:

  Namespace expense {{Public Partial Square ExpenseReportPage: Page {... } Public Partial Category MediaElement Example: Page {MediaElement myMediaElementExample = New MediaElement (); Public Media Illustration Example () {} Public Zero OnMouseDownPlayMedia (Object Sender, RoutedEventArgs args) / MouseButtonEventArgs {// Play system will launch media if it is currently not active or // resumed the media if it is stopped If there is a media already running, then there is no effect. I myMediaElementExample.Play (); }}}  

Homepage. Xll.cs File:

  Namespace expense for this {public partial home page: Page {MediaElementExample mediaElementExample = new MediaElementExample (); Public Homepage () {InitializeComponent (); } Zero handclick (Object Sender, Routing Avent ARG E) {button as srcButton = e.Source button; SrcButton.Width = 200; Media Element Example OnMouseDownplayMedia (Sender, E); Enclosing the line for debugging purposes:  
   

MyMediaElementExample.Play ();

with a try {} hold {} with block:

  try {myMediaElementExample.Play (); } (Pre-exception) {// Print either exception or test it in debugger}  

This will give you more information due to the exception. If this is still unclear then update the question with this new information.

If myMediaElementExample was zero, then I expected you to see that you will get one instead of Wenz 32. You can see the myMediaElementExample.Play (); You can check by setting a break point on the line.

Once you find out the problem and decide, you can remove the exception handler or if you want to be cautious, leave it, but to trap exceptions that < Code> MediaElement.Play wakes up.


No comments:

Post a Comment