objc2-avf-audio 0.3.2

Bindings to the AVFAudio framework
Documentation
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayer?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVAudioPlayer;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for AVAudioPlayer {}
);

impl AVAudioPlayer {
    extern_methods!(
        #[unsafe(method(initWithContentsOfURL:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithContentsOfURL_error(
            this: Allocated<Self>,
            url: &NSURL,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[unsafe(method(initWithData:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithData_error(
            this: Allocated<Self>,
            data: &NSData,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[unsafe(method(initWithContentsOfURL:fileTypeHint:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithContentsOfURL_fileTypeHint_error(
            this: Allocated<Self>,
            url: &NSURL,
            uti_string: Option<&NSString>,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[unsafe(method(initWithData:fileTypeHint:error:_))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithData_fileTypeHint_error(
            this: Allocated<Self>,
            data: &NSData,
            uti_string: Option<&NSString>,
        ) -> Result<Retained<Self>, Retained<NSError>>;

        #[unsafe(method(prepareToPlay))]
        #[unsafe(method_family = none)]
        pub unsafe fn prepareToPlay(&self) -> bool;

        #[unsafe(method(play))]
        #[unsafe(method_family = none)]
        pub unsafe fn play(&self) -> bool;

        #[unsafe(method(playAtTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn playAtTime(&self, time: NSTimeInterval) -> bool;

        #[unsafe(method(pause))]
        #[unsafe(method_family = none)]
        pub unsafe fn pause(&self);

        #[unsafe(method(stop))]
        #[unsafe(method_family = none)]
        pub unsafe fn stop(&self);

        #[unsafe(method(isPlaying))]
        #[unsafe(method_family = none)]
        pub unsafe fn isPlaying(&self) -> bool;

        #[unsafe(method(numberOfChannels))]
        #[unsafe(method_family = none)]
        pub unsafe fn numberOfChannels(&self) -> NSUInteger;

        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> NSTimeInterval;

        #[unsafe(method(currentDevice))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentDevice(&self) -> Option<Retained<NSString>>;

        /// Setter for [`currentDevice`][Self::currentDevice].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCurrentDevice:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCurrentDevice(&self, current_device: Option<&NSString>);

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub unsafe fn delegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn AVAudioPlayerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn AVAudioPlayerDelegate>>,
        );

        #[unsafe(method(url))]
        #[unsafe(method_family = none)]
        pub unsafe fn url(&self) -> Option<Retained<NSURL>>;

        #[unsafe(method(data))]
        #[unsafe(method_family = none)]
        pub unsafe fn data(&self) -> Option<Retained<NSData>>;

        #[unsafe(method(pan))]
        #[unsafe(method_family = none)]
        pub unsafe fn pan(&self) -> c_float;

        /// Setter for [`pan`][Self::pan].
        #[unsafe(method(setPan:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setPan(&self, pan: c_float);

        #[unsafe(method(volume))]
        #[unsafe(method_family = none)]
        pub unsafe fn volume(&self) -> c_float;

        /// Setter for [`volume`][Self::volume].
        #[unsafe(method(setVolume:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setVolume(&self, volume: c_float);

        #[unsafe(method(setVolume:fadeDuration:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setVolume_fadeDuration(&self, volume: c_float, duration: NSTimeInterval);

        #[unsafe(method(enableRate))]
        #[unsafe(method_family = none)]
        pub unsafe fn enableRate(&self) -> bool;

        /// Setter for [`enableRate`][Self::enableRate].
        #[unsafe(method(setEnableRate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setEnableRate(&self, enable_rate: bool);

        #[unsafe(method(rate))]
        #[unsafe(method_family = none)]
        pub unsafe fn rate(&self) -> c_float;

        /// Setter for [`rate`][Self::rate].
        #[unsafe(method(setRate:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRate(&self, rate: c_float);

        #[unsafe(method(currentTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentTime(&self) -> NSTimeInterval;

        /// Setter for [`currentTime`][Self::currentTime].
        #[unsafe(method(setCurrentTime:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setCurrentTime(&self, current_time: NSTimeInterval);

        #[unsafe(method(deviceCurrentTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn deviceCurrentTime(&self) -> NSTimeInterval;

        #[unsafe(method(numberOfLoops))]
        #[unsafe(method_family = none)]
        pub unsafe fn numberOfLoops(&self) -> NSInteger;

        /// Setter for [`numberOfLoops`][Self::numberOfLoops].
        #[unsafe(method(setNumberOfLoops:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setNumberOfLoops(&self, number_of_loops: NSInteger);

        #[unsafe(method(settings))]
        #[unsafe(method_family = none)]
        pub unsafe fn settings(&self) -> Retained<NSDictionary<NSString, AnyObject>>;

        #[cfg(feature = "AVAudioFormat")]
        #[unsafe(method(format))]
        #[unsafe(method_family = none)]
        pub unsafe fn format(&self) -> Retained<AVAudioFormat>;

        #[unsafe(method(isMeteringEnabled))]
        #[unsafe(method_family = none)]
        pub unsafe fn isMeteringEnabled(&self) -> bool;

        /// Setter for [`isMeteringEnabled`][Self::isMeteringEnabled].
        #[unsafe(method(setMeteringEnabled:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setMeteringEnabled(&self, metering_enabled: bool);

        #[unsafe(method(updateMeters))]
        #[unsafe(method_family = none)]
        pub unsafe fn updateMeters(&self);

        #[unsafe(method(peakPowerForChannel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn peakPowerForChannel(&self, channel_number: NSUInteger) -> c_float;

        #[unsafe(method(averagePowerForChannel:))]
        #[unsafe(method_family = none)]
        pub unsafe fn averagePowerForChannel(&self, channel_number: NSUInteger) -> c_float;

        #[cfg(feature = "AVAudioSessionRoute")]
        #[unsafe(method(channelAssignments))]
        #[unsafe(method_family = none)]
        pub unsafe fn channelAssignments(
            &self,
        ) -> Option<Retained<NSArray<AVAudioSessionChannelDescription>>>;

        #[cfg(feature = "AVAudioSessionRoute")]
        /// Setter for [`channelAssignments`][Self::channelAssignments].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setChannelAssignments:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setChannelAssignments(
            &self,
            channel_assignments: Option<&NSArray<AVAudioSessionChannelDescription>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl AVAudioPlayer {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayerdelegate?language=objc)
    pub unsafe trait AVAudioPlayerDelegate: NSObjectProtocol {
        #[optional]
        #[unsafe(method(audioPlayerDidFinishPlaying:successfully:))]
        #[unsafe(method_family = none)]
        unsafe fn audioPlayerDidFinishPlaying_successfully(
            &self,
            player: &AVAudioPlayer,
            flag: bool,
        );

        #[optional]
        #[unsafe(method(audioPlayerDecodeErrorDidOccur:error:))]
        #[unsafe(method_family = none)]
        unsafe fn audioPlayerDecodeErrorDidOccur_error(
            &self,
            player: &AVAudioPlayer,
            error: Option<&NSError>,
        );
    }
);