Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / August 2007

Tip: Looking for answers? Try searching our database.

SoundPlayer vs PlaySound

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kingherc - 21 Aug 2007 11:46 GMT
Hello there,

I am programming a simple game for Windows Mobile, managed code C# with .NET
compact framework. In the game, I want to play some sounds (which I've stored
as sound resources in my project) when some actions occur. I found two ways:
The Media.Soundplayer .NET class and the PlaySound API method. I tried both
ways and there is a problem:

The API call to PlaySound just works fine, doesn't have any glitch.
The SoundPlayer.Play method has a serious glitch. The game stucks for about
a second (or half a second) before the sound begins to play. Is there
something wrong with the SoundPlayer.Play method, or am I doing something
wrong?
Peter Foot [MVP] - 21 Aug 2007 15:53 GMT
Hi,

I assume you are using .NETCF v3.5 beta as prior versions don't have the
System.Media classes. The way this class works is it loads in the file
internally and plays from the local cache of data. PlaySound simply plays
directly from the given file path (or memory buffer). You can work around
this by calling the Load() or LoadAsync() methods elsewhere in your code
prior to needing the sound. If the load is already done Play should perform
much better. Currently Play is having to first load the file which explains
the delay.

Peter

Signature

Peter Foot
Microsoft Device Application Development MVP
www.peterfoot.net | www.inthehand.com
In The Hand Ltd - .NET Solutions for Mobility

> Hello there,
>
[quoted text clipped - 14 lines]
> something wrong with the SoundPlayer.Play method, or am I doing something
> wrong?
Kingherc - 21 Aug 2007 17:22 GMT
Thanks Peter for your quick response,
& congrats for your MVP

Well, I had tried what you said, in two ways: loading the sound from a file,
and loading the sound from a MemoryStream. They presented glitches. But in
the end I found out what the real problem was: Not surprisingly, I was
running the program always through Visual Studio (which monitors the program
while debugging and imposes a certain load on it), and that was why the
SoundPlayer presented glitches. I ran the program by itself and everything
worked just fine. Thanks for your response.
I should comment that SoundPlayer was a very nice addition in v3.5.

> Hi,
>
[quoted text clipped - 27 lines]
> > something wrong with the SoundPlayer.Play method, or am I doing something
> > wrong?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.