Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,20 @@ private void LoadStream(bool loadSync)
int streamLen = (int)_stream.Length;
_currentPos = 0;
_streamData = new byte[streamLen];
_stream.Read(_streamData, 0, streamLen);
#if NET7_0_OR_GREATER
_stream.ReadExactly(_streamData);
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we backport this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int totalRead = 0;
while (totalRead < streamLen)
{
int bytesRead = _stream.Read(_streamData, totalRead, streamLen - totalRead);
if (bytesRead <= 0)
{
throw new EndOfStreamException();
}
totalRead += bytesRead;
}
#endif
IsLoadCompleted = true;
OnLoadCompleted(new AsyncCompletedEventArgs(null, false, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,22 @@ public void PlayLooping_NullStream_Success()
player.PlayLooping();
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsSoundPlaySupported))]
[MemberData(nameof(Play_String_TestData))]
[OuterLoop]
public void PlaySync_TrickledData_Success(string sourceLocation)
{
using var player = new SoundPlayer();
player.Stream = new TrickleStream(File.ReadAllBytes(sourceLocation.Replace("file://", "")));
player.PlaySync();
}

private sealed 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));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsSoundPlaySupported))]
[OuterLoop]
public void PlaySync_NullStream_Success()
Expand Down