#[repr(C)]pub struct AVPlayer { /* private fields */ }AVPlayer only.Expand description
Implementations§
Source§impl AVPlayer
impl AVPlayer
Sourcepub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
Initializes an AVPlayer with no player items.
Sourcepub unsafe fn playerWithURL(
url: &NSURL,
mtm: MainThreadMarker,
) -> Retained<Self>
pub unsafe fn playerWithURL( url: &NSURL, mtm: MainThreadMarker, ) -> Retained<Self>
Returns an instance of AVPlayer that plays a single audiovisual resource referenced by URL.
Parameter URL:
Returns: An instance of AVPlayer
Implicitly creates an AVPlayerItem. Clients can obtain the AVPlayerItem as it becomes the player’s currentItem.
Sourcepub unsafe fn playerWithPlayerItem(
item: Option<&AVPlayerItem>,
mtm: MainThreadMarker,
) -> Retained<Self>
Available on crate feature AVPlayerItem only.
pub unsafe fn playerWithPlayerItem( item: Option<&AVPlayerItem>, mtm: MainThreadMarker, ) -> Retained<Self>
AVPlayerItem only.Create an AVPlayer that plays a single audiovisual item.
Parameter item:
Returns: An instance of AVPlayer
Useful in order to play items for which an AVAsset has previously been created. See -[AVPlayerItem initWithAsset:].
Sourcepub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>
pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>
Initializes an AVPlayer that plays a single audiovisual resource referenced by URL.
Parameter URL:
Returns: An instance of AVPlayer
Implicitly creates an AVPlayerItem. Clients can obtain the AVPlayerItem as it becomes the player’s currentItem.
Sourcepub unsafe fn initWithPlayerItem(
this: Allocated<Self>,
item: Option<&AVPlayerItem>,
) -> Retained<Self>
Available on crate feature AVPlayerItem only.
pub unsafe fn initWithPlayerItem( this: Allocated<Self>, item: Option<&AVPlayerItem>, ) -> Retained<Self>
AVPlayerItem only.Create an AVPlayer that plays a single audiovisual item.
Parameter item:
Returns: An instance of AVPlayer
Useful in order to play items for which an AVAsset has previously been created. See -[AVPlayerItem initWithAsset:]. This method throws an exception if the item is not an AVPlayerItem, or if the item is associated with another AVPlayer.
Sourcepub unsafe fn status(&self) -> AVPlayerStatus
pub unsafe fn status(&self) -> AVPlayerStatus
The ability of the receiver to be used for playback.
The value of this property is an AVPlayerStatus that indicates whether the receiver can be used for playback. When the value of this property is AVPlayerStatusFailed, the receiver can no longer be used for playback and a new instance needs to be created in its place. When this happens, clients can check the value of the error property to determine the nature of the failure. This property is key value observable.
Sourcepub unsafe fn error(&self) -> Option<Retained<NSError>>
pub unsafe fn error(&self) -> Option<Retained<NSError>>
If the receiver’s status is AVPlayerStatusFailed, this describes the error that caused the failure.
The value of this property is an NSError that describes what caused the receiver to no longer be able to play items. If the receiver’s status is not AVPlayerStatusFailed, the value of this property is nil.
Source§impl AVPlayer
Methods declared on superclass NSObject.
impl AVPlayer
Methods declared on superclass NSObject.
pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>
Source§impl AVPlayer
AVPlayerPlaybackControl.
impl AVPlayer
AVPlayerPlaybackControl.
Sourcepub unsafe fn rate(&self) -> c_float
pub unsafe fn rate(&self) -> c_float
Indicates the desired rate of playback; 0.0 means “paused”, 1.0 indicates a desire to play at the natural rate of the current item.
Setting the value of rate to 0.0 pauses playback, causing the value of timeControlStatus to change to AVPlayerTimeControlStatusPaused. Setting the rate to a non-zero value causes the value of timeControlStatus to become either AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate or AVPlayerTimeControlStatusPlaying, depending on whether sufficient media data has been buffered for playback to occur and whether the player’s default behavior of waiting in order to minimize stalling is permitted. See discussion of AVPlayerTimeControlStatus for more details.
AVPlayer can reset the desired rate to 0.0 when a change in overall state requires playback to be halted, such as when an interruption occurs on iOS, as announced by AVAudioSession, or when the playback buffer becomes empty and playback stalls while automaticallyWaitsToMinimizeStalling is NO.
The effective rate of playback may differ from the desired rate even while timeControlStatus is AVPlayerTimeControlStatusPlaying, if the processing algorithm in use for managing audio pitch requires quantization of playback rate. For information about quantization of rates for audio processing, see AVAudioProcessingSettings.h. You can always obtain the effective rate of playback from the currentItem’s timebase; see the timebase property of AVPlayerItem.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
Sourcepub unsafe fn defaultRate(&self) -> c_float
pub unsafe fn defaultRate(&self) -> c_float
Indicates the rate at which to start playback when play is called; defaults to 1.0.
Setting this property does not imply playback starts automatically at this rate. Clients still have to kick off playback using play. Note that using setRate to start playback will skip using the value in this property nor would it update this property. Therefore, setRate:1.0 is no longer recommended as a means to start playback. Use play instead. Use setRate for operations like scanning where the rate is to be updated instantaneously. Invoking play again would restore playback at the rate set in this property.
The effective rate of playback may still differ from the default rate subject to restrictions imposed by the system. See documentation for the rate property for a discussion on when the desired rate does not translate to effective rate.
Sourcepub unsafe fn setDefaultRate(&self, default_rate: c_float)
pub unsafe fn setDefaultRate(&self, default_rate: c_float)
Setter for defaultRate.
Sourcepub unsafe fn play(&self)
pub unsafe fn play(&self)
Signals the desire to begin playback at the rate set in the defaultRate.
For releases up to iOS version 16.0, macOS versions 13.0, tvOS 16.0 and watchOS 9.0, this is equivalent to setting the value of rate to 1.0. Starting from iOS version 16.0, macOS versions 13.0, tvOS 16.0 and watchOS 9.0, this will attempt to use the rate set in the defaultRate property. The effective rate of playback may differ from the defaultRate due to the reasons mentioned in the documentation of the rate property. Clients interested in knowing the effective rate can listen for AVPlayerRateDidChangeNotification notification.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Sourcepub unsafe fn pause(&self)
pub unsafe fn pause(&self)
Pauses playback.
Equivalent to setting the value of rate to 0.0.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Sourcepub unsafe fn timeControlStatus(&self) -> AVPlayerTimeControlStatus
pub unsafe fn timeControlStatus(&self) -> AVPlayerTimeControlStatus
Indicates whether playback is currently paused indefinitely, suspended while waiting for appropriate conditions, or in progress.
For possible values and discussion, see AVPlayerTimeControlStatus.
When automaticallyWaitsToMinimizeStalling is YES, absent intervention in the form of invocations of -setRate: or -pause or, on iOS, an interruption that requires user intervention before playback can resume, the value of the property timeControlStatus automatically changes between AVPlayerTimeControlStatusPlaying and AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate depending on whether sufficient media data is available to continue playback. This property is key value observable.
Sourcepub unsafe fn reasonForWaitingToPlay(
&self,
) -> Option<Retained<AVPlayerWaitingReason>>
pub unsafe fn reasonForWaitingToPlay( &self, ) -> Option<Retained<AVPlayerWaitingReason>>
Indicates the reason for waiting when the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate
When the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate, this property describes why the player is currently waiting. It is nil otherwise. You can use the value of reasonForWaitingToPlay to show UI indicating the player’s waiting state conditionally. This property is key value observable. Possible values are AVPlayerWaitingWithNoItemToPlayReason, AVPlayerWaitingWhileEvaluatingBufferingRateReason, and AVPlayerWaitingToMinimizeStallsReason.
Sourcepub unsafe fn playImmediatelyAtRate(&self, rate: c_float)
pub unsafe fn playImmediatelyAtRate(&self, rate: c_float)
Immediately plays the available media data at the specified rate.
When the player’s currentItem has a value of NO for playbackBufferEmpty, this method causes the value of rate to change to the specified rate, the value of timeControlStatus to change to AVPlayerTimeControlStatusPlaying, and the receiver to play the available media immediately, whether or not prior buffering of media data is sufficient to ensure smooth playback. If insufficient media data is buffered for playback to start (e.g. if the current item has a value of YES for playbackBufferEmpty), the receiver will act as if the buffer became empty during playback, except that no AVPlayerItemPlaybackStalledNotification will be posted.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Source§impl AVPlayer
AVPlayerItemControl.
impl AVPlayer
AVPlayerItemControl.
pub unsafe fn currentItem(&self) -> Option<Retained<AVPlayerItem>>
AVPlayerItem only.Sourcepub unsafe fn replaceCurrentItemWithPlayerItem(
&self,
item: Option<&AVPlayerItem>,
)
Available on crate feature AVPlayerItem only.
pub unsafe fn replaceCurrentItemWithPlayerItem( &self, item: Option<&AVPlayerItem>, )
AVPlayerItem only.Replaces the player’s current item with the specified player item.
Parameter item: The AVPlayerItem that will become the player’s current item.
In all releases of iOS 4, invoking replaceCurrentItemWithPlayerItem: with an AVPlayerItem that’s already the receiver’s currentItem results in an exception being raised. Starting with iOS 5, it’s a no-op. This method throws an exception if the item already exists in the play queue.
Sourcepub unsafe fn actionAtItemEnd(&self) -> AVPlayerActionAtItemEnd
pub unsafe fn actionAtItemEnd(&self) -> AVPlayerActionAtItemEnd
Indicates the action that the player should perform when playback of an item reaches its end time.
This property throws an exception if set to AVPlayerActionAtItemEndAdvance on an AVPlayer which is not an AVQueuePlayer.
Sourcepub unsafe fn setActionAtItemEnd(
&self,
action_at_item_end: AVPlayerActionAtItemEnd,
)
pub unsafe fn setActionAtItemEnd( &self, action_at_item_end: AVPlayerActionAtItemEnd, )
Setter for actionAtItemEnd.
Source§impl AVPlayer
AVPlayerTimeControl.
impl AVPlayer
AVPlayerTimeControl.
Sourcepub unsafe fn currentTime(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn currentTime(&self) -> CMTime
objc2-core-media only.Returns the current time of the current item.
Returns: A CMTime
Returns the current time of the current item. Not key-value observable; use -addPeriodicTimeObserverForInterval:queue:usingBlock: instead.
Sourcepub unsafe fn seekToDate(&self, date: &NSDate)
pub unsafe fn seekToDate(&self, date: &NSDate)
Moves the playback cursor.
Parameter date:
Use this method to seek to a specified time for the current player item.
The time seeked to may differ from the specified time for efficiency. For sample accurate seeking see seekToTime:toleranceBefore:toleranceAfter:.
Sourcepub unsafe fn seekToDate_completionHandler(
&self,
date: &NSDate,
completion_handler: &Block<dyn Fn(Bool)>,
)
Available on crate feature block2 only.
pub unsafe fn seekToDate_completionHandler( &self, date: &NSDate, completion_handler: &Block<dyn Fn(Bool)>, )
block2 only.Moves the playback cursor and invokes the specified block when the seek operation has either been completed or been interrupted.
Parameter date:
Parameter completionHandler:
Use this method to seek to a specified time for the current player item and to be notified when the seek operation is complete.
The completion handler for any prior seek request that is still in process will be invoked immediately with the finished parameter
set to NO. If the new request completes without being interrupted by another seek request or by any other operation the specified
completion handler will be invoked with the finished parameter set to YES. If no item is attached, the completion handler will be
invoked immediately with the finished parameter set to NO.
Sourcepub unsafe fn seekToTime(&self, time: CMTime)
Available on crate feature objc2-core-media only.
pub unsafe fn seekToTime(&self, time: CMTime)
objc2-core-media only.Moves the playback cursor.
Parameter time:
Use this method to seek to a specified time for the current player item.
The time seeked to may differ from the specified time for efficiency. For sample accurate seeking see seekToTime:toleranceBefore:toleranceAfter:.
Sourcepub unsafe fn seekToTime_toleranceBefore_toleranceAfter(
&self,
time: CMTime,
tolerance_before: CMTime,
tolerance_after: CMTime,
)
Available on crate feature objc2-core-media only.
pub unsafe fn seekToTime_toleranceBefore_toleranceAfter( &self, time: CMTime, tolerance_before: CMTime, tolerance_after: CMTime, )
objc2-core-media only.Moves the playback cursor within a specified time bound.
Parameter time:
Parameter toleranceBefore:
Parameter toleranceAfter:
Use this method to seek to a specified time for the current player item.
The time seeked to will be within the range [time-toleranceBefore, time+toleranceAfter] and may differ from the specified time for efficiency.
Pass kCMTimeZero for both toleranceBefore and toleranceAfter to request sample accurate seeking which may incur additional decoding delay.
Messaging this method with beforeTolerance:kCMTimePositiveInfinity and afterTolerance:kCMTimePositiveInfinity is the same as messaging seekToTime: directly.
Sourcepub unsafe fn seekToTime_completionHandler(
&self,
time: CMTime,
completion_handler: &Block<dyn Fn(Bool)>,
)
Available on crate features block2 and objc2-core-media only.
pub unsafe fn seekToTime_completionHandler( &self, time: CMTime, completion_handler: &Block<dyn Fn(Bool)>, )
block2 and objc2-core-media only.Moves the playback cursor and invokes the specified block when the seek operation has either been completed or been interrupted.
Parameter time:
Parameter completionHandler:
Use this method to seek to a specified time for the current player item and to be notified when the seek operation is complete.
The completion handler for any prior seek request that is still in process will be invoked immediately with the finished parameter
set to NO. If the new request completes without being interrupted by another seek request or by any other operation the specified
completion handler will be invoked with the finished parameter set to YES. If no item is attached, the completion handler will be
invoked immediately with the finished parameter set to NO.
Sourcepub unsafe fn seekToTime_toleranceBefore_toleranceAfter_completionHandler(
&self,
time: CMTime,
tolerance_before: CMTime,
tolerance_after: CMTime,
completion_handler: &Block<dyn Fn(Bool)>,
)
Available on crate features block2 and objc2-core-media only.
pub unsafe fn seekToTime_toleranceBefore_toleranceAfter_completionHandler( &self, time: CMTime, tolerance_before: CMTime, tolerance_after: CMTime, completion_handler: &Block<dyn Fn(Bool)>, )
block2 and objc2-core-media only.Moves the playback cursor within a specified time bound and invokes the specified block when the seek operation has either been completed or been interrupted.
Parameter time:
Parameter toleranceBefore:
Parameter toleranceAfter:
Use this method to seek to a specified time for the current player item and to be notified when the seek operation is complete.
The time seeked to will be within the range [time-toleranceBefore, time+toleranceAfter] and may differ from the specified time for efficiency.
Pass kCMTimeZero for both toleranceBefore and toleranceAfter to request sample accurate seeking which may incur additional decoding delay.
Messaging this method with beforeTolerance:kCMTimePositiveInfinity and afterTolerance:kCMTimePositiveInfinity is the same as messaging seekToTime: directly.
The completion handler for any prior seek request that is still in process will be invoked immediately with the finished parameter set to NO. If the new
request completes without being interrupted by another seek request or by any other operation the specified completion handler will be invoked with the
finished parameter set to YES. If no item is attached, the completion handler will be invoked immediately with the finished parameter set to NO.
Source§impl AVPlayer
AVPlayerAdvancedRateControl.
impl AVPlayer
AVPlayerAdvancedRateControl.
Sourcepub unsafe fn automaticallyWaitsToMinimizeStalling(&self) -> bool
pub unsafe fn automaticallyWaitsToMinimizeStalling(&self) -> bool
Indicates that the player is allowed to delay playback at the specified rate in order to minimize stalling
When this property is YES, whenever 1) the rate is set from zero to non-zero or 2) the playback buffer becomes empty and playback stalls, the player will attempt to determine if, at the specified rate, its currentItem will play to the end without interruptions. Should it determine that such interruptions would occur and these interruptions can be avoided by delaying the start or resumption of playback, the value of timeControlStatus will become AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate and playback will start automatically when the likelihood of stalling has been minimized.
You may want to set this property to NO when you need precise control over playback start times, e.g., when synchronizing multiple instances of AVPlayer, and you should set it to NO if you use an AVAssetResourceLoader delegate to load media data (more on this below). If the value of this property is NO, reasonForWaitingToPlay cannot assume a value of AVPlayerWaitingToMinimizeStallsReason. This implies that setting rate to a non-zero value in AVPlayerTimeControlStatusPaused will cause playback to start immediately as long as the playback buffer is not empty. When the playback buffer becomes empty during AVPlayerTimeControlStatusPlaying and playback stalls, playback state will switch to AVPlayerTimeControlStatusPaused and the rate will become 0.0.
Changing the value of this property to NO while the value of timeControlStatus is AVPlayerTimeControlStatusWaitingToPlayAtSpecifiedRate with a reasonForWaitingToPlay of AVPlayerWaitingToMinimizeStallsReason will cause the player to attempt playback at the specified rate immediately.
For clients linked against iOS 10.0 and running on that version or later or linked against macOS 10.12 and running on that version or later, the default value of this property is YES. In versions of iOS prior to iOS 10.0 and versions of macOS prior to 10.12, this property is unavailable, and the behavior of the AVPlayer corresponds to the type of content being played. For streaming content, including HTTP Live Streaming, the AVPlayer acts as if automaticallyWaitsToMinimizeStalling is YES. For file-based content, including file-based content accessed via progressive http download, the AVPlayer acts as if automaticallyWaitsToMinimizeStalling is NO.
If you employ an AVAssetResourceLoader delegate that loads media data for playback, you should set the value of your AVPlayer’s automaticallyWaitsToMinimizeStalling property to NO. Allowing the value of automaticallyWaitsToMinimizeStalling to remain YES when an AVAssetResourceLoader delegate is used for the loading of media data can result in poor start-up times for playback and poor recovery from stalls, because the behaviors provided by AVPlayer when automaticallyWaitsToMinimizeStalling has a value of YES depend on predictions of the future availability of media data that that do not function as expected when data is loaded via a client-controlled means, using the AVAssetResourceLoader delegate interface.
You can allow the value of automaticallyWaitsToMinimizeStalling to remain YES if you use an AVAssetResourceLoader delegate to manage content keys for FairPlay Streaming, to provide dynamically-generated master playlists for HTTP Live Streaming, or to respond to authentication challenges, but not to load media data for playback.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
Sourcepub unsafe fn setAutomaticallyWaitsToMinimizeStalling(
&self,
automatically_waits_to_minimize_stalling: bool,
)
pub unsafe fn setAutomaticallyWaitsToMinimizeStalling( &self, automatically_waits_to_minimize_stalling: bool, )
Setter for automaticallyWaitsToMinimizeStalling.
Sourcepub unsafe fn setRate_time_atHostTime(
&self,
rate: c_float,
item_time: CMTime,
host_clock_time: CMTime,
)
Available on crate feature objc2-core-media only.
pub unsafe fn setRate_time_atHostTime( &self, rate: c_float, item_time: CMTime, host_clock_time: CMTime, )
objc2-core-media only.Simultaneously sets the playback rate and the relationship between the current item’s current time and host time.
You can use this function to synchronize playback with an external activity.
The current item’s timebase is adjusted so that its time will be (or was) itemTime when host time is (or was) hostClockTime. In other words: if hostClockTime is in the past, the timebase’s time will be interpolated as though the timebase has been running at the requested rate since that time. If hostClockTime is in the future, the timebase will immediately start running at the requested rate from an earlier time so that it will reach the requested itemTime at the requested hostClockTime. (Note that the item’s time will not jump backwards, but instead will sit at itemTime until the timebase reaches that time.)
Note that setRate:time:atHostTime: is not supported when automaticallyWaitsToMinimizeStalling is YES. For clients linked against iOS 10.0 and later or macOS 12.0 and later, invoking setRate:time:atHostTime: when automaticallyWaitsToMinimizeStalling is YES will raise an NSInvalidArgument exception. Support for HTTP Live Streaming content requires iOS 11, tvOS 11, macOS 10.13 or later.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Parameter itemTime: The time to start playback from, specified precisely (i.e., with zero tolerance).
Pass kCMTimeInvalid to use the current item’s current time.
Parameter hostClockTime: The host time at which to start playback.
If hostClockTime is specified, the player will not ensure that media data is loaded before the timebase starts moving.
If hostClockTime is kCMTimeInvalid, the rate and time will be set together, but without external synchronization;
a host time in the near future will be used, allowing some time for media data loading.
Sourcepub unsafe fn prerollAtRate_completionHandler(
&self,
rate: c_float,
completion_handler: Option<&Block<dyn Fn(Bool)>>,
)
Available on crate feature block2 only.
pub unsafe fn prerollAtRate_completionHandler( &self, rate: c_float, completion_handler: Option<&Block<dyn Fn(Bool)>>, )
block2 only.Begins loading media data to prime the render pipelines for playback from the current time with the given rate.
Once the completion handler is called with YES, the player’s rate can be set with minimal latency. The completion handler will be called with NO if the preroll is interrupted by a time change or incompatible rate change, or if preroll is not possible for some other reason. Call this method only when the rate is currently zero and only after the AVPlayer’s status has become AVPlayerStatusReadyToPlay. This method throws an exception if the status is not AVPlayerStatusReadyToPlay.
Parameter rate: The intended rate for subsequent playback.
Parameter completionHandler: The block that will be called when the preroll is either completed or is interrupted.
Sourcepub unsafe fn cancelPendingPrerolls(&self)
pub unsafe fn cancelPendingPrerolls(&self)
Cancel any pending preroll requests and invoke the corresponding completion handlers if present.
Use this method to cancel and release the completion handlers for pending prerolls. The finished parameter of the completion handlers will be set to NO.
Sourcepub unsafe fn sourceClock(&self) -> Option<Retained<CMClock>>
Available on crate feature objc2-core-media only.
pub unsafe fn sourceClock(&self) -> Option<Retained<CMClock>>
objc2-core-media only.Set to override the automatic choice of source clock for item timebases.
NULL by default. This is most useful for synchronizing video-only movies with audio played via other means. IMPORTANT NOTE: If you specify a source clock other than the appropriate audio device clock, audio may drift out of sync.
Sourcepub unsafe fn setSourceClock(&self, source_clock: Option<&CMClock>)
Available on crate feature objc2-core-media only.
pub unsafe fn setSourceClock(&self, source_clock: Option<&CMClock>)
objc2-core-media only.Setter for sourceClock.
Source§impl AVPlayer
AVPlayerTimeObservation.
impl AVPlayer
AVPlayerTimeObservation.
Sourcepub unsafe fn removeTimeObserver(&self, observer: &AnyObject)
pub unsafe fn removeTimeObserver(&self, observer: &AnyObject)
Cancels a previously registered time observer.
Parameter observer: An object returned by a previous call to -addPeriodicTimeObserverForInterval:queue:usingBlock: or -addBoundaryTimeObserverForTimes:queue:usingBlock:.
Upon return, the caller is guaranteed that no new time observer blocks will begin executing. Depending on the calling thread and the queue used to add the time observer, an in-flight block may continue to execute after this method returns. You can guarantee synchronous time observer removal by enqueuing the call to -removeTimeObserver: on that queue. Alternatively, call dispatch_sync(queue, ^{}) after -removeTimeObserver: to wait for any in-flight blocks to finish executing. -removeTimeObserver: should be used to explicitly cancel each time observer added using -addPeriodicTimeObserverForInterval:queue:usingBlock: and -addBoundaryTimeObserverForTimes:queue:usingBlock:.
This method throws an exception for any of the following reasons:
- observer was added by a different instance of AVPlayer
- observer was not returned by -addPeriodicTimeObserverForInterval:queue:usingBlock:
- observer was not returned by -addBoundaryTimeObserverForTimes:queue:usingBlock:
Source§impl AVPlayer
AVPlayerAutomaticMediaSelection.
impl AVPlayer
AVPlayerAutomaticMediaSelection.
pub unsafe fn appliesMediaSelectionCriteriaAutomatically(&self) -> bool
Sourcepub unsafe fn setAppliesMediaSelectionCriteriaAutomatically(
&self,
applies_media_selection_criteria_automatically: bool,
)
pub unsafe fn setAppliesMediaSelectionCriteriaAutomatically( &self, applies_media_selection_criteria_automatically: bool, )
Setter for appliesMediaSelectionCriteriaAutomatically.
Sourcepub unsafe fn setMediaSelectionCriteria_forMediaCharacteristic(
&self,
criteria: Option<&AVPlayerMediaSelectionCriteria>,
media_characteristic: &AVMediaCharacteristic,
)
Available on crate features AVMediaFormat and AVPlayerMediaSelectionCriteria only.
pub unsafe fn setMediaSelectionCriteria_forMediaCharacteristic( &self, criteria: Option<&AVPlayerMediaSelectionCriteria>, media_characteristic: &AVMediaCharacteristic, )
AVMediaFormat and AVPlayerMediaSelectionCriteria only.Applies automatic selection criteria for media that has the specified media characteristic.
Parameter criteria: An instance of AVPlayerMediaSelectionCriteria.
Parameter mediaCharacteristic: The media characteristic for which the selection criteria are to be applied. Supported values include AVMediaCharacteristicAudible, AVMediaCharacteristicLegible, and AVMediaCharacteristicVisual.
Criteria will be applied to an AVPlayerItem when: a) It is made ready to play b) Specific media selections are made by -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:] in a different group. The automatic choice in one group may be influenced by a specific selection in another group. c) Underlying system preferences change, e.g. system language, accessibility captions.
Specific selections made by -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:] within any group will override automatic selection in that group until -[AVPlayerItem selectMediaOptionAutomaticallyInMediaSelectionGroup:] is received.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Sourcepub unsafe fn mediaSelectionCriteriaForMediaCharacteristic(
&self,
media_characteristic: &AVMediaCharacteristic,
) -> Option<Retained<AVPlayerMediaSelectionCriteria>>
Available on crate features AVMediaFormat and AVPlayerMediaSelectionCriteria only.
pub unsafe fn mediaSelectionCriteriaForMediaCharacteristic( &self, media_characteristic: &AVMediaCharacteristic, ) -> Option<Retained<AVPlayerMediaSelectionCriteria>>
AVMediaFormat and AVPlayerMediaSelectionCriteria only.Returns the automatic selection criteria for media that has the specified media characteristic.
Parameter mediaCharacteristic: The media characteristic for which the selection criteria is to be returned. Supported values include AVMediaCharacteristicAudible, AVMediaCharacteristicLegible, and AVMediaCharacteristicVisual.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
Source§impl AVPlayer
AVPlayerAudioDeviceSupport.
impl AVPlayer
AVPlayerAudioDeviceSupport.
Sourcepub unsafe fn audioOutputDeviceUniqueID(&self) -> Option<Retained<NSString>>
pub unsafe fn audioOutputDeviceUniqueID(&self) -> Option<Retained<NSString>>
Specifies the unique ID of the Core Audio output device used to play audio.
By default, the value of this property is nil, indicating that the default audio output device is used. Otherwise the value of this property is an NSString containing the unique ID of the Core Audio output device to be used for audio output.
Core Audio’s kAudioDevicePropertyDeviceUID is a suitable source of audio output device unique IDs.
Sourcepub unsafe fn setAudioOutputDeviceUniqueID(
&self,
audio_output_device_unique_id: Option<&NSString>,
)
pub unsafe fn setAudioOutputDeviceUniqueID( &self, audio_output_device_unique_id: Option<&NSString>, )
Setter for audioOutputDeviceUniqueID.
Source§impl AVPlayer
AVPlayerExternalPlaybackSupport.
impl AVPlayer
AVPlayerExternalPlaybackSupport.
pub unsafe fn allowsExternalPlayback(&self) -> bool
Sourcepub unsafe fn setAllowsExternalPlayback(&self, allows_external_playback: bool)
pub unsafe fn setAllowsExternalPlayback(&self, allows_external_playback: bool)
Setter for allowsExternalPlayback.
pub unsafe fn isExternalPlaybackActive(&self) -> bool
pub unsafe fn usesExternalPlaybackWhileExternalScreenIsActive(&self) -> bool
Sourcepub unsafe fn setUsesExternalPlaybackWhileExternalScreenIsActive(
&self,
uses_external_playback_while_external_screen_is_active: bool,
)
pub unsafe fn setUsesExternalPlaybackWhileExternalScreenIsActive( &self, uses_external_playback_while_external_screen_is_active: bool, )
Setter for usesExternalPlaybackWhileExternalScreenIsActive.
pub unsafe fn externalPlaybackVideoGravity( &self, ) -> Retained<AVLayerVideoGravity>
AVAnimation only.Sourcepub unsafe fn setExternalPlaybackVideoGravity(
&self,
external_playback_video_gravity: &AVLayerVideoGravity,
)
Available on crate feature AVAnimation only.
pub unsafe fn setExternalPlaybackVideoGravity( &self, external_playback_video_gravity: &AVLayerVideoGravity, )
AVAnimation only.Setter for externalPlaybackVideoGravity.
Source§impl AVPlayer
AVPlayerProtectedContent.
impl AVPlayer
AVPlayerProtectedContent.
Sourcepub unsafe fn outputObscuredDueToInsufficientExternalProtection(&self) -> bool
pub unsafe fn outputObscuredDueToInsufficientExternalProtection(&self) -> bool
Whether or not decoded output is being obscured due to insufficient external protection.
The value of this property indicates whether the player is purposefully obscuring the visual output of the current item because the requirement for an external protection mechanism is not met by the current device configuration. It is highly recommended that clients whose content requires external protection observe this property and set the playback rate to zero and display an appropriate user interface when the value changes to YES. This property is key value observable.
Note that the value of this property is dependent on the external protection requirements of the current item. These requirements are inherent to the content itself and cannot be externally specified. If the current item does not require external protection, the value of this property will be NO.
Source§impl AVPlayer
AVPlayerPlaybackCapabilities.
impl AVPlayer
AVPlayerPlaybackCapabilities.
Sourcepub unsafe fn availableHDRModes(mtm: MainThreadMarker) -> AVPlayerHDRMode
👎Deprecated: Use eligibleForHDRPlayback instead
pub unsafe fn availableHDRModes(mtm: MainThreadMarker) -> AVPlayerHDRMode
An AVPlayerHDRMode value that indicates the HDR modes the device can play to an appropriate display. A value of 0 indicates that no HDR modes are supported.
This property indicates all of the HDR modes that the device can play. Each value indicates that an appropriate HDR display is available for the specified HDR mode. Additionally, the device must be capable of playing the specified HDR type. This property does not indicate whether video contains HDR content, whether HDR video is currently playing, or whether video is playing on an HDR display.
Sourcepub unsafe fn eligibleForHDRPlayback(mtm: MainThreadMarker) -> bool
pub unsafe fn eligibleForHDRPlayback(mtm: MainThreadMarker) -> bool
Indicates whether HDR content can be played to an appropriate display.
This property is YES if an HDR display is available and the device is capable of playing HDR content from an appropriate AVAsset, NO otherwise. This property does not indicate whether video contains HDR content, whether HDR video is currently playing, or whether video is playing on an HDR display. This property is not KVO observable.
Source§impl AVPlayer
AVPlayerVideoDecoderGPUSupport.
impl AVPlayer
AVPlayerVideoDecoderGPUSupport.
Sourcepub unsafe fn preferredVideoDecoderGPURegistryID(&self) -> u64
pub unsafe fn preferredVideoDecoderGPURegistryID(&self) -> u64
Specifies a registryID associated with a GPU that should be used for video decode.
By default, whenever possible, video decode will be performed on the GPU associated with the display on which the presenting CALayer is located. Decode will be transitioned to a new GPU if appropriate when the CALayer moves to a new display. This property overrides this default behavior, forcing decode to prefer an affinity to the GPU specified regardless of which GPU is being used to display the associated CALayer.
The GPU registryID can be obtained from the GPU MTLDevice using [MTLDevice registryID] or can be obtained from OpenGL or OpenCL.
Sourcepub unsafe fn setPreferredVideoDecoderGPURegistryID(
&self,
preferred_video_decoder_gpu_registry_id: u64,
)
pub unsafe fn setPreferredVideoDecoderGPURegistryID( &self, preferred_video_decoder_gpu_registry_id: u64, )
Setter for preferredVideoDecoderGPURegistryID.
Source§impl AVPlayer
AVPlayerVideoDisplaySleepPrevention.
impl AVPlayer
AVPlayerVideoDisplaySleepPrevention.
Sourcepub unsafe fn preventsDisplaySleepDuringVideoPlayback(&self) -> bool
pub unsafe fn preventsDisplaySleepDuringVideoPlayback(&self) -> bool
Indicates whether video playback prevents display and device sleep.
Default is YES on iOS, tvOS and in Mac Catalyst apps. Default is NO on macOS. Setting this property to NO does not force the display to sleep, it simply stops preventing display sleep. Other apps or frameworks within your app may still be preventing display sleep for various reasons.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
Sourcepub unsafe fn setPreventsDisplaySleepDuringVideoPlayback(
&self,
prevents_display_sleep_during_video_playback: bool,
)
pub unsafe fn setPreventsDisplaySleepDuringVideoPlayback( &self, prevents_display_sleep_during_video_playback: bool, )
Setter for preventsDisplaySleepDuringVideoPlayback.
Source§impl AVPlayer
AVPlayerAutomaticBackgroundPrevention.
impl AVPlayer
AVPlayerAutomaticBackgroundPrevention.
Sourcepub unsafe fn preventsAutomaticBackgroundingDuringVideoPlayback(&self) -> bool
pub unsafe fn preventsAutomaticBackgroundingDuringVideoPlayback(&self) -> bool
Indicates whether video playback prevents the app from automatically getting backgrounded.
Default value is YES. Setting this property to YES prevents an application that is playing video from automatically getting backgrounded. This property does not prevent the user from backgrounding the application.
Sourcepub unsafe fn setPreventsAutomaticBackgroundingDuringVideoPlayback(
&self,
prevents_automatic_backgrounding_during_video_playback: bool,
)
pub unsafe fn setPreventsAutomaticBackgroundingDuringVideoPlayback( &self, prevents_automatic_backgrounding_during_video_playback: bool, )
Source§impl AVPlayer
AVPlayerBackgroundSupport.
impl AVPlayer
AVPlayerBackgroundSupport.
Sourcepub unsafe fn audiovisualBackgroundPlaybackPolicy(
&self,
) -> AVPlayerAudiovisualBackgroundPlaybackPolicy
pub unsafe fn audiovisualBackgroundPlaybackPolicy( &self, ) -> AVPlayerAudiovisualBackgroundPlaybackPolicy
Controls the policy to be used in deciding how playback of audiovisual content should continue while the application transitions to background.
By default, the system is free to decide the background playback policy (AVPlayerAudiovisualBackgroundPlaybackPolicyAutomatic). If set to AVPlayerAudiovisualBackgroundPlaybackPolicyPauses, player will be paused on entering background. If set to AVPlayerAudiovisualBackgroundPlaybackPolicyContinuesIfPossible, the system makes the best effort to continue playback but the app also needs appropriate UIBackgroundModes for the system to let it continue running in the background. Note that this policy only applies to items with enabled video.
Sourcepub unsafe fn setAudiovisualBackgroundPlaybackPolicy(
&self,
audiovisual_background_playback_policy: AVPlayerAudiovisualBackgroundPlaybackPolicy,
)
pub unsafe fn setAudiovisualBackgroundPlaybackPolicy( &self, audiovisual_background_playback_policy: AVPlayerAudiovisualBackgroundPlaybackPolicy, )
Setter for audiovisualBackgroundPlaybackPolicy.
Source§impl AVPlayer
PlaybackCoordination.
impl AVPlayer
PlaybackCoordination.
Sourcepub unsafe fn playbackCoordinator(
&self,
) -> Retained<AVPlayerPlaybackCoordinator>
Available on crate feature AVPlaybackCoordinator only.
pub unsafe fn playbackCoordinator( &self, ) -> Retained<AVPlayerPlaybackCoordinator>
AVPlaybackCoordinator only.The playback coordinator for this player.
If the playback coordinator is connected to other participants, rate changes and seeks on the current item will be automatically mirrored to all connected participants. Depending on policies, the coordinator may also intercept rate changes to non-zero to coordinate playback start with the rest of the group. Use [AVPlayer playImmediatelyAtRate:] to override the coordinated startup behavior and start playback immediately. This is useful to give users an opportunity to override waiting caused by other participants’ suspensions. Player configuration other than rate and seeks are not communicated to other participants and can be configured independently by each participant. A player with a connected playbackCoordinator will change behavior in situations that require the player to pause for internal reasons, such as a route change or a stall. When resuming after these events, the player will not resume at the stop time. Instead, it will attempt to rejoin the group, potentially seeking to match the other participant’s progress. It is left to the owner of the AVPlayer to ensure that all participants are playing the same item. See the discussion of AVPlaybackCoordinator for considerations about item transitions.
Source§impl AVPlayer
AVPlayerOutputSupport.
impl AVPlayer
AVPlayerOutputSupport.
Sourcepub unsafe fn videoOutput(&self) -> Option<Retained<AVPlayerVideoOutput>>
Available on crate feature AVPlayerOutput only.
pub unsafe fn videoOutput(&self) -> Option<Retained<AVPlayerVideoOutput>>
AVPlayerOutput only.The video output for this player, if one was set.
When an AVPlayerVideoOutput is associated with an AVPlayer, the AVPlayerVideoOutput can then be used to receive video-related samples during playback.
Note: If an output is set while AVPlayer has a current item it may cause different data channels to be selected for that item, which can have a performance impact. As a result, when possible, it is best to set an output before setting items on an AVPlayer.
Sourcepub unsafe fn setVideoOutput(&self, video_output: Option<&AVPlayerVideoOutput>)
Available on crate feature AVPlayerOutput only.
pub unsafe fn setVideoOutput(&self, video_output: Option<&AVPlayerVideoOutput>)
AVPlayerOutput only.Setter for videoOutput.
Source§impl AVPlayer
AVPlayerDeprecated.
impl AVPlayer
AVPlayerDeprecated.
Sourcepub unsafe fn isClosedCaptionDisplayEnabled(&self) -> bool
👎Deprecated: Allow AVPlayer to enable closed captions automatically according to user preferences by ensuring that the value of appliesMediaSelectionCriteriaAutomatically is YES.
pub unsafe fn isClosedCaptionDisplayEnabled(&self) -> bool
Indicates whether display of closed captions is enabled.
This property is deprecated.
When the value of appliesMediaSelectionCriteriaAutomatically is YES, the receiver will enable closed captions automatically either according to user preferences or, if you provide them, according to AVPlayerMediaSelectionCriteria for the media characteristic AVMediaCharacteristicLegible.
If you want to determine whether closed captions may be available for a given AVPlayerItem, you can examine the AVMediaSelectionOptions in the AVMediaSelectionGroup for the characteristic AVMediaCharacteristicLegible, as vended by -[AVAsset mediaSelectionGroupForMediaCharacteristic:]. See AVMediaCharacteristicTranscribesSpokenDialogForAccessibility and AVMediaCharacteristicDescribesMusicAndSoundForAccessibility as documented in AVMediaFormat.h for information about how to identify legible media selection options that offer the features of closed captions for accessibility purposes.
You can select or deselect a specific AVMediaSelectionOption via -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:].
For further information about Media Accessibility preferences, see MediaAccessibility framework documentation.
Sourcepub unsafe fn setClosedCaptionDisplayEnabled(
&self,
closed_caption_display_enabled: bool,
)
👎Deprecated: Allow AVPlayer to enable closed captions automatically according to user preferences by ensuring that the value of appliesMediaSelectionCriteriaAutomatically is YES.
pub unsafe fn setClosedCaptionDisplayEnabled( &self, closed_caption_display_enabled: bool, )
Setter for isClosedCaptionDisplayEnabled.
pub unsafe fn masterClock(&self) -> Option<Retained<CMClock>>
objc2-core-media only.Sourcepub unsafe fn setMasterClock(&self, master_clock: Option<&CMClock>)
👎DeprecatedAvailable on crate feature objc2-core-media only.
pub unsafe fn setMasterClock(&self, master_clock: Option<&CMClock>)
objc2-core-media only.Setter for masterClock.
impl AVPlayer
AVPlayerInterstitialSupport.
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
pub fn class(&self) -> &'static AnyClass
Dynamically find the class of this object.
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AVPlayer> for AVQueuePlayer
impl AsRef<AVPlayer> for AVQueuePlayer
Source§impl Borrow<AVPlayer> for AVQueuePlayer
impl Borrow<AVPlayer> for AVQueuePlayer
Source§impl ClassType for AVPlayer
impl ClassType for AVPlayer
Source§const NAME: &'static str = "AVPlayer"
const NAME: &'static str = "AVPlayer"
Source§type ThreadKind = dyn MainThreadOnly
type ThreadKind = dyn MainThreadOnly
Source§impl NSObjectProtocol for AVPlayer
impl NSObjectProtocol for AVPlayer
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_refSource§fn isMemberOfClass(&self, cls: &AnyClass) -> bool
fn isMemberOfClass(&self, cls: &AnyClass) -> bool
Source§fn respondsToSelector(&self, aSelector: Sel) -> bool
fn respondsToSelector(&self, aSelector: Sel) -> bool
Source§fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
fn conformsToProtocol(&self, aProtocol: &AnyProtocol) -> bool
Source§fn debugDescription(&self) -> Retained<NSObject>
fn debugDescription(&self) -> Retained<NSObject>
Source§impl RefEncode for AVPlayer
impl RefEncode for AVPlayer
Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
impl DowncastTarget for AVPlayer
impl Eq for AVPlayer
Auto Trait Implementations§
impl !Freeze for AVPlayer
impl !RefUnwindSafe for AVPlayer
impl !Send for AVPlayer
impl !Sync for AVPlayer
impl !Unpin for AVPlayer
impl !UnwindSafe for AVPlayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<'a, T> MainThreadOnly for T
impl<'a, T> MainThreadOnly for T
Source§fn mtm(&self) -> MainThreadMarker
fn mtm(&self) -> MainThreadMarker
MainThreadMarker from the main-thread-only object. Read more