简体   繁体   中英

MediaElement causes audible clicks

I'm developing a game, a Windows Store App based on XAML (not DirectX). To play sound effects (WAV files), I use the MediaElement . For every sound effect there is one (or several) MediaElement(s) that I initialize like this:

StorageFolder folder = 
    await Package.Current.InstalledLocation.GetFolderAsync(FolderPath);
StorageFile file = await folder.GetFileAsync(FileName);
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

_mediaElement = new MediaElement();
_parentPanel.Children.Add(_mediaElement);
_mediaElement.AutoPlay = false;
_mediaElement.SetSource(stream, file.ContentType);

...and play like this:

_mediaElement.Play();

This works, but sometimes there are annoying audible clicks, like this .

The strange thing is how consistent the clicks are: Some files never cause a click, some almost always and if they do it's always at the same position (for one it's the very beginning, for another it's close to the end). The clicks are not in the WAV files. When I play them in Audacity, everything is fine.

What's going on, here? How do I remedy this?

I'd suggest using XAudio2, SharpDX or MonoGame for sounds. As you noticed MediaElements are not geared towards that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM