Skip to content
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

[AudioToolbox] Make P/Invokes in SystemSound.cs have blittable signatures. #19677

Merged
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
24 changes: 20 additions & 4 deletions src/AudioToolbox/SystemSound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,20 @@ public Task PlaySystemSoundAsync ()
unsafe static extern void AudioServicesPlaySystemSoundWithCompletion (uint inSystemSoundID, BlockLiteral* inCompletionBlock);

[DllImport (Constants.AudioToolboxLibrary)]
static extern AudioServicesError AudioServicesCreateSystemSoundID (IntPtr fileUrl, out uint soundId);
unsafe static extern AudioServicesError AudioServicesCreateSystemSoundID (IntPtr fileUrl, uint* soundId);

static uint Create (NSUrl fileUrl)
{
AudioServicesError error;
uint soundId;

if (fileUrl is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fileUrl));

var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId);
unsafe {
error = AudioServicesCreateSystemSoundID (fileUrl.Handle, &soundId);
}

if (error != AudioServicesError.None)
throw new InvalidOperationException (string.Format ("Could not create system sound ID for url {0}; error={1}",
fileUrl, error));
Expand All @@ -312,22 +318,32 @@ public SystemSound (NSUrl fileUrl)

public static SystemSound? FromFile (NSUrl fileUrl)
{
AudioServicesError error;
uint soundId;

if (fileUrl is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fileUrl));

var error = AudioServicesCreateSystemSoundID (fileUrl.Handle, out var soundId);
unsafe {
error = AudioServicesCreateSystemSoundID (fileUrl.Handle, &soundId);
}
if (error != AudioServicesError.None)
return null;
return new SystemSound (soundId, true);
}

public static SystemSound? FromFile (string filename)
{
AudioServicesError error;
uint soundId;

if (filename is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (filename));

using (var url = new NSUrl (filename)) {
var error = AudioServicesCreateSystemSoundID (url.Handle, out var soundId);
unsafe {
error = AudioServicesCreateSystemSoundID (url.Handle, &soundId);
}
if (error != AudioServicesError.None)
return null;
return new SystemSound (soundId, true);
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public partial class BlittablePInvokes {
"AudioToolbox.AudioQueueStatus AudioToolbox.OutputAudioQueue::AudioQueueSetOfflineRenderFormat(System.IntPtr,AudioToolbox.AudioStreamBasicDescription&,System.IntPtr)",
"AudioToolbox.AudioServicesError AudioToolbox.AudioServices::AudioServicesGetProperty(AudioToolbox.AudioServicesPropertyKey,System.UInt32,System.UInt32&,System.UInt32&,System.UInt32&)",
"AudioToolbox.AudioServicesError AudioToolbox.AudioServices::AudioServicesSetProperty(AudioToolbox.AudioServicesPropertyKey,System.UInt32,System.UInt32&,System.UInt32,System.UInt32&)",
"AudioToolbox.AudioServicesError AudioToolbox.SystemSound::AudioServicesCreateSystemSoundID(System.IntPtr,System.UInt32&)",
"AudioToolbox.MusicPlayerStatus AudioToolbox.MusicPlayer::MusicPlayerGetBeatsForHostTime(System.IntPtr,System.Int64,System.Double&)",
"AudioToolbox.MusicPlayerStatus AudioToolbox.MusicPlayer::MusicPlayerGetHostTimeForBeats(System.IntPtr,System.Double,System.Int64&)",
"AudioToolbox.MusicPlayerStatus AudioToolbox.MusicPlayer::MusicPlayerGetPlayRateScalar(System.IntPtr,System.Double&)",
Expand Down