dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.35k stars 4.74k forks source link

System.Media.SoundPlayer doesn't play specific encoding Lavf58.29.100 #82494

Open tarekgh opened 1 year ago

tarekgh commented 1 year ago

Description

This is reported through the VS community portal https://developercommunity.visualstudio.com/t/SystemMediaSoundPlayer-doesnt-play-sp/10169184. We moved this here as the issue reproduce on .NET too.

have a wav audio file with Lavf58.29.100 meta tag that is getting an error saying that is not a wav valid audio file, but when using FFMpeg to change the encoding to 59.33.100 and using ADPCM as well, the new wav audio start to work on this code, so i was wondering if this encoding is not supported on System.Media.PlayerSound

using (var sound = new System.Media.SoundPlayer(path)) { sound.PlaySync(); }

The first image is about the converted audio file, that has Lavf59.33.100 ADPCM Encoding and the second has the Lavf58.29.100.

image

image

Reproduction Steps

Try to play any WAV file encoded with Lavf58.29.100

using (var sound = new System.Media.SoundPlayer(path)) { sound.PlaySync(); }

Expected behavior

The sound will play.

Actual behavior

It fail to play with error message

Regression?

No

Known Workarounds

Convert the WAV file to use other encoding

Configuration

All .NET and .NET Framework versions

Other information

No response

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-microsoft-win32 See info in area-owners.md if you want to be subscribed.

Issue Details
### Description This is reported through the VS community portal https://developercommunity.visualstudio.com/t/SystemMediaSoundPlayer-doesnt-play-sp/10169184. We moved this here as the issue reproduce on .NET too. have a wav audio file that has a Lavf58.29.100 that is getting an error saying that is not a wav valid audio file, but when using FFMpeg to change the encoding to 59.33.100 and using ADPCM as well, the new wav audio start to work on this code, so i was wondering if this encoding is not supported on System.Media.PlayerSound using (var sound = new System.Media.SoundPlayer(path)) { sound.PlaySync(); } The first image is about the converted audio file, that has Lavf59.33.100 ADPCM Encoding and the second has the Lavf58.29.100. ![image](https://user-images.githubusercontent.com/10833894/220701289-705b7a5b-87a1-4db0-9f2e-dde27a91e778.png) ![image](https://user-images.githubusercontent.com/10833894/220701339-6abecf50-d37e-4e1e-b26b-7b295ca6e604.png) ### Reproduction Steps Try to play any WAV file encoded with `Lavf58.29.100` using (var sound = new System.Media.SoundPlayer(path)) { sound.PlaySync(); } ### Expected behavior The sound will play. ### Actual behavior It fail to play with error message ### Regression? No ### Known Workarounds Convert the WAV file to use other encoding ### Configuration All .NET and .NET Framework versions ### Other information _No response_
Author: tarekgh
Assignees: -
Labels: `area-Microsoft.Win32`, `untriaged`
Milestone: -
hopperpl commented 1 year ago

As a note, "Lavf58.29.100" respectively " Lavf59.33.100" are not encoding formats, it is simply a meta tag of ffmpeg's libavformat library in the .wav file.

The first (working) file is encoded in WAVE_FORMAT_ADPCM, the second (not working) is encoded in WAVE_FORMAT_PCM. (https://learn.microsoft.com/en-us/windows/win32/api/mmeapi/ns-mmeapi-waveformatex)

#define WAVE_FORMAT_PCM    0x0001
#define WAVE_FORMAT_ADPCM  0x0002

(this is what ffmpeg prints as audio tag)


In the second image ffmpeg is complaining, that the 'data' chunk has an invalid size. This has most likely caused the issue with the SoundPlayer, the .wav file is simply corrupt.

See yellow text: Ignoring maximum wave data size, file may be invalid

A solution would be for the .wav parser in the SoundPlayer to correct an invalid 'data' chunk size. I've seen many times that wave-writers set the value to int.MaxValue when recording as the final size is (still) unknown when they start.