diff --git a/src/AudioToolbox/SystemSound.cs b/src/AudioToolbox/SystemSound.cs index 05a723705d26..23fbca9a364d 100644 --- a/src/AudioToolbox/SystemSound.cs +++ b/src/AudioToolbox/SystemSound.cs @@ -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)); @@ -312,10 +318,15 @@ 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); @@ -323,11 +334,16 @@ public SystemSound (NSUrl fileUrl) 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); diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index eb6ca058d6e4..f58d8eca3c19 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -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&)",