

This was Frustration #5 for me, as it took me a while to get past the problem of the "Value of Type 'String' cannot be converted to 'System.URI.'" error. It has an Open method which loads the file in the form of a URI. However, there is no advantage that I know of and in fact, the syntax is slightly more verbose and it also caused Frustration #4 - the fact that the audio file will only play once and then needs to be 'reset' by calling its Stop method the Stop method apparently has the effect of returning the playhead to the beginning of the file. (If you have a need to create a media object in XAML and have it play, pause, stop, trigger, etc, only in XAML then the MediaElement will be your tool of choice.)īefore abandoning the MediaElement approach altogether, I should point out that you can create the MediaElement in XAML and then access it's properties and methods in code. Keeping to my approach of doing all the work in code, I'm therefore going to home in on the MediaPlayer. And this is a job for either the MediaPlayer or MediaElement.
#Netsound how to
So it's always useful to know how to use the lighter weight SoundPlayer if you run into these problems in the future. In some situations on particular systems you will have problems getting the two Media components to work properly. In many cases, the MediaPlayer or MediaElement will be a better option, but there is a good reason why I included the discussion of the SoundPlayer above. It only understands wav format files and you can generally only play one wav file at a time (unless you start to get quite fancy with multithreading).

In addition to the standard Play method, the SoundPlayer has a PlaySync method - in case you should rather unusually want the system to be locked until the sound has finished playing.Īnd finally if you want a sound to be repeatedly played, you can use the PlayLooping method to drive people mad sanity can be restored by inserting the Stop method!Īs you've already seen, the SoundPlayer has some limitations. I have tried it on several PCs, each with different sound card configurations and the problems occur on them all.

Private Sub btnResource_Click( ByVal sender As System.Object, ByVal e As ) Handles btnResource.Clickĭim player As New SoundPlayer( My.Resources.canon)Įven with small, well tested files I often found that using this approach I would get a lot of unacceptable sound distortion (actually additional unrelated sounds to that expected).
