-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SoundPlayer from Stream doesn't work for partial reads #80264
Comments
Related: |
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsRepro: using System.Media;
byte[] wav = File.ReadAllBytes(@"C:\Windows\Media\chimes.wav");
var player = new SoundPlayer();
player.Stream = new TrickleStream(wav);
player.PlaySync();
class TrickleStream : MemoryStream
{
public TrickleStream(byte[] bytes) : base(bytes) { }
public override int Read(byte[] buffer, int offset, int count) =>
base.Read(buffer, offset, Math.Min(count, 1));
public override int Read(Span<byte> buffer) =>
base.Read(buffer.IsEmpty ? buffer : buffer.Slice(0, 1));
} That should play a chime but instead crashes with an exception about the audio data's header being invalid. That's because it assumes that Stream.Read will always return as much data as was requested, which is not a valid assumption:
cc: @eerhardt
|
Tagging subscribers to this area: @dotnet/area-microsoft-win32 Issue DetailsRepro: using System.Media;
byte[] wav = File.ReadAllBytes(@"C:\Windows\Media\chimes.wav");
var player = new SoundPlayer();
player.Stream = new TrickleStream(wav);
player.PlaySync();
class TrickleStream : MemoryStream
{
public TrickleStream(byte[] bytes) : base(bytes) { }
public override int Read(byte[] buffer, int offset, int count) =>
base.Read(buffer, offset, Math.Min(count, 1));
public override int Read(Span<byte> buffer) =>
base.Read(buffer.IsEmpty ? buffer : buffer.Slice(0, 1));
} That should play a chime but instead crashes with an exception about the audio data's header being invalid. That's because it assumes that Stream.Read will always return as much data as was requested, which is not a valid assumption:
cc: @eerhardt
|
Repro:
That should play a chime but instead crashes with an exception about the audio data's header being invalid. That's because it assumes that Stream.Read will always return as much data as was requested, which is not a valid assumption:
runtime/src/libraries/System.Windows.Extensions/src/System/Media/SoundPlayer.cs
Line 313 in 1928cd2
cc: @eerhardt
The text was updated successfully, but these errors were encountered: