pub struct AVPlayerItem { /* private fields */ }AVPlayerItem only.Expand description
An AVPlayerItem carries a reference to an AVAsset as well as presentation settings for that asset.
Note that inspection of media assets is provided by AVAsset. This class is intended to represent presentation state for an asset that’s played by an AVPlayer and to permit observation of that state.
It is important to avoid key-value observation with a key path containing the asset’s property. Observe the AVPlayerItem’s property instead. For example, use the “duration” key path instead of the “asset.duration” key path.
To allow clients to add and remove their objects as key-value observers safely, AVPlayerItem serializes notifications of changes that occur dynamically during playback on the same dispatch queue on which notifications of playback state changes are serialized by its associated AVPlayer. By default, this queue is the main queue. See dispatch_get_main_queue().
See also Apple’s documentation
Implementations§
Source§impl AVPlayerItem
AVPlayerInterstitialSupport.
impl AVPlayerItem
AVPlayerInterstitialSupport.
Sourcepub unsafe fn automaticallyHandlesInterstitialEvents(&self) -> bool
Available on crate feature AVPlayerInterstitialEventController only.
pub unsafe fn automaticallyHandlesInterstitialEvents(&self) -> bool
AVPlayerInterstitialEventController only.Allows interstitials to be played according to a schedule that’s specified by server-side directives. The default value is YES. A value of NO prevents automatic scheduling of future server-side interstitial events. Events specified by an AVPlayerInterstitialEventController override server-side events, regardless of the value of this property.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
Sourcepub unsafe fn setAutomaticallyHandlesInterstitialEvents(
&self,
automatically_handles_interstitial_events: bool,
)
Available on crate feature AVPlayerInterstitialEventController only.
pub unsafe fn setAutomaticallyHandlesInterstitialEvents( &self, automatically_handles_interstitial_events: bool, )
AVPlayerInterstitialEventController only.Setter for automaticallyHandlesInterstitialEvents.
Sourcepub unsafe fn templatePlayerItem(&self) -> Option<Retained<AVPlayerItem>>
Available on crate feature AVPlayerInterstitialEventController only.
pub unsafe fn templatePlayerItem(&self) -> Option<Retained<AVPlayerItem>>
AVPlayerInterstitialEventController only.If the item was created automatically according to a template item for looping, for interstitial playback, or for other purposes, indicates the AVPlayerItem that was used as the template.
Source§impl AVPlayerItem
impl AVPlayerItem
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>
Sourcepub unsafe fn playerItemWithURL(
url: &NSURL,
mtm: MainThreadMarker,
) -> Retained<Self>
pub unsafe fn playerItemWithURL( url: &NSURL, mtm: MainThreadMarker, ) -> Retained<Self>
Returns an instance of AVPlayerItem for playing a resource at the specified location.
Equivalent to +playerItemWithAsset:, passing [AVAsset assetWithURL:URL] as the value of asset.
-
Parameter URL:
-
Returns: An instance of AVPlayerItem.
Sourcepub unsafe fn playerItemWithAsset(
asset: &AVAsset,
mtm: MainThreadMarker,
) -> Retained<Self>
Available on crate feature AVAsset only.
pub unsafe fn playerItemWithAsset( asset: &AVAsset, mtm: MainThreadMarker, ) -> Retained<Self>
AVAsset only.Returns an instance of AVPlayerItem for playing an AVAsset.
Equivalent to +playerItemWithAsset:automaticallyLoadedAssetKeys:, passing @ [ “ duration“ ] as the value of automaticallyLoadedAssetKeys.
This method, along with the companion asset property, is MainActor-isolated for Swift clients because AVAsset is not Sendable. If you are using a Sendable subclass of AVAsset, such as AVURLAsset, an overload of this initializer will be chosen automatically to allow you to initialize an AVPlayerItem while not running on the main actor.
-
Parameter asset:
-
Returns: An instance of AVPlayerItem.
Sourcepub unsafe fn playerItemWithAsset_automaticallyLoadedAssetKeys(
asset: &AVAsset,
automatically_loaded_asset_keys: Option<&NSArray<NSString>>,
mtm: MainThreadMarker,
) -> Retained<Self>
Available on crate feature AVAsset only.
pub unsafe fn playerItemWithAsset_automaticallyLoadedAssetKeys( asset: &AVAsset, automatically_loaded_asset_keys: Option<&NSArray<NSString>>, mtm: MainThreadMarker, ) -> Retained<Self>
AVAsset only.Returns an instance of AVPlayerItem for playing an AVAsset.
The value of each key in automaticallyLoadedAssetKeys will be automatically be loaded by the underlying AVAsset before the receiver achieves the status AVPlayerItemStatusReadyToPlay; i.e. when the item is ready to play, the value of -[[AVPlayerItem asset] statusOfValueForKey:error:] will be one of the terminal status values greater than AVKeyValueStatusLoading.
This method, along with the companion asset property, is MainActor-isolated for Swift clients because AVAsset is not Sendable. If you are using a Sendable subclass of AVAsset, such as AVURLAsset, you can use init(asset:automaticallyLoadedAssetKeys:) to initialize an AVPlayerItem while not running on the main actor.
-
Parameter asset:
-
Parameter automaticallyLoadedAssetKeys: An NSArray of NSStrings, each representing a property key defined by AVAsset. See AVAsset.h for property keys, e.g. duration.
-
Returns: An instance of AVPlayerItem.
Sourcepub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>
pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Retained<Self>
Initializes an AVPlayerItem with an NSURL.
Equivalent to -initWithAsset:, passing [AVAsset assetWithURL:URL] as the value of asset.
-
Parameter URL:
-
Returns: An instance of AVPlayerItem
Sourcepub unsafe fn initWithAsset(
this: Allocated<Self>,
asset: &AVAsset,
) -> Retained<Self>
Available on crate feature AVAsset only.
pub unsafe fn initWithAsset( this: Allocated<Self>, asset: &AVAsset, ) -> Retained<Self>
AVAsset only.Initializes an AVPlayerItem with an AVAsset.
Equivalent to -initWithAsset:automaticallyLoadedAssetKeys:, passing @ [ “ duration“ ] as the value of automaticallyLoadedAssetKeys.
This method, along with the companion asset property, is MainActor-isolated for Swift clients because AVAsset is not Sendable. If you are using a Sendable subclass of AVAsset, such as AVURLAsset, an overload of this initializer will be chosen automatically to allow you to initialize an AVPlayerItem while not running on the main actor.
-
Parameter asset:
-
Returns: An instance of AVPlayerItem
Sourcepub unsafe fn initWithAsset_automaticallyLoadedAssetKeys(
this: Allocated<Self>,
asset: &AVAsset,
automatically_loaded_asset_keys: Option<&NSArray<NSString>>,
) -> Retained<Self>
Available on crate feature AVAsset only.
pub unsafe fn initWithAsset_automaticallyLoadedAssetKeys( this: Allocated<Self>, asset: &AVAsset, automatically_loaded_asset_keys: Option<&NSArray<NSString>>, ) -> Retained<Self>
AVAsset only.Initializes an AVPlayerItem with an AVAsset.
The value of each key in automaticallyLoadedAssetKeys will be automatically be loaded by the underlying AVAsset before the receiver achieves the status AVPlayerItemStatusReadyToPlay; i.e. when the item is ready to play, the value of -[[AVPlayerItem asset] statusOfValueForKey:error:] will be one of the terminal status values greater than AVKeyValueStatusLoading.
This method, along with the companion asset property, is MainActor-isolated for Swift clients because AVAsset is not Sendable. If you are using a Sendable subclass of AVAsset, such as AVURLAsset, you can use init(asset:automaticallyLoadedAssetKeys:) to initialize an AVPlayerItem while not running on the main actor.
-
Parameter asset: An instance of AVAsset.
-
Parameter automaticallyLoadedAssetKeys: An NSArray of NSStrings, each representing a property key defined by AVAsset. See AVAsset.h for property keys, e.g. duration.
-
Returns: An instance of AVPlayerItem
Sourcepub unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Retained<AnyObject>
pub unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Retained<AnyObject>
§Safety
zone must be a valid pointer or null.
pub unsafe fn copy(&self) -> Retained<AnyObject>
Sourcepub unsafe fn status(&self) -> AVPlayerItemStatus
pub unsafe fn status(&self) -> AVPlayerItemStatus
The ability of the receiver to be used for playback.
The value of this property is an AVPlayerItemStatus that indicates whether the receiver can be used for playback. When the value of this property is AVPlayerItemStatusFailed, 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. The value of this property will not be updated after the receiver is removed from an AVPlayer. 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 AVPlayerItemStatusFailed, 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 be played. If the receiver’s status is not AVPlayerItemStatusFailed, the value of this property is nil.
Source§impl AVPlayerItem
AVPlayerItemInspection.
impl AVPlayerItem
AVPlayerItemInspection.
Sourcepub unsafe fn asset(&self) -> Retained<AVAsset>
Available on crate feature AVAsset only.
pub unsafe fn asset(&self) -> Retained<AVAsset>
AVAsset only.Accessor for underlying AVAsset.
Sourcepub unsafe fn tracks(&self) -> Retained<NSArray<AVPlayerItemTrack>>
Available on crate feature AVPlayerItemTrack only.
pub unsafe fn tracks(&self) -> Retained<NSArray<AVPlayerItemTrack>>
AVPlayerItemTrack only.Provides array of AVPlayerItem tracks. Observable (can change dynamically during playback).
The value of this property will accord with the properties of the underlying media resource when the receiver becomes ready to play. Before the underlying media resource has been sufficiently loaded, its value is an empty NSArray. Use key-value observation to obtain a valid array of tracks as soon as it becomes available.
Sourcepub unsafe fn duration(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn duration(&self) -> CMTime
objc2-core-media only.Indicates the duration of the item, not considering either its forwardPlaybackEndTime or reversePlaybackEndTime.
This property is observable. The duration of an item can change dynamically during playback.
Unless you omit “ duration“ from the array of asset keys you pass to +playerItemWithAsset:automaticallyLoadedAssetKeys: or -initWithAsset:automaticallyLoadedAssetKeys:, the value of this property will accord with the properties of the underlying AVAsset and the current state of playback once the receiver becomes ready to play.
Before the underlying duration has been loaded, the value of this property is kCMTimeIndefinite. Use key-value observation to obtain a valid duration as soon as it becomes available. (Note that the value of duration may remain kCMTimeIndefinite, e.g. for live streams.)
Sourcepub unsafe fn presentationSize(&self) -> CGSize
Available on crate feature objc2-core-foundation only.
pub unsafe fn presentationSize(&self) -> CGSize
objc2-core-foundation only.The size of the receiver as presented by the player.
Indicates the size at which the visual portion of the item is presented by the player; can be scaled from this size to fit within the bounds of an AVPlayerLayer via its videoGravity property. Can be scaled arbitrarily for presentation via the frame property of an AVPlayerLayer.
The value of this property will accord with the properties of the underlying media resource when the receiver becomes ready to play. Before the underlying media resource is sufficiently loaded, its value is CGSizeZero. Use key-value observation to obtain a valid presentationSize as soon as it becomes available. (Note that the value of presentationSize may remain CGSizeZero, e.g. for audio-only items.)
Sourcepub unsafe fn timedMetadata(&self) -> Option<Retained<NSArray<AVMetadataItem>>>
👎Deprecated: Use AVPlayerItemMetadataOutput to obtain timed metadataAvailable on crate feature AVMetadataItem only.
pub unsafe fn timedMetadata(&self) -> Option<Retained<NSArray<AVMetadataItem>>>
AVMetadataItem only.Provides an NSArray of AVMetadataItems representing the timed metadata encountered most recently within the media as it plays. May be nil.
Notifications of changes are available via key-value observation. As an optimization for playback, AVPlayerItem may omit the processing of timed metadata when no observer of this property is registered. Therefore, when no such observer is registered, the value of the timedMetadata property may remain nil regardless of the contents of the underlying media.
This property must be accessed on the main thread/queue.
Sourcepub unsafe fn automaticallyLoadedAssetKeys(&self) -> Retained<NSArray<NSString>>
pub unsafe fn automaticallyLoadedAssetKeys(&self) -> Retained<NSArray<NSString>>
An array of property keys defined on AVAsset. The value of each key in the array is automatically loaded while the receiver is being made ready to play.
The value of each key in automaticallyLoadedAssetKeys will be automatically be loaded by the underlying AVAsset before the receiver achieves the status AVPlayerItemStatusReadyToPlay; i.e. when the item is ready to play, the value of -[[AVPlayerItem asset] statusOfValueForKey:error:] will be AVKeyValueStatusLoaded. If loading of any of the values fails, the status of the AVPlayerItem will change instead to AVPlayerItemStatusFailed..
Source§impl AVPlayerItem
AVPlayerItemRateAndSteppingSupport.
impl AVPlayerItem
AVPlayerItemRateAndSteppingSupport.
Sourcepub unsafe fn canPlayFastForward(&self) -> bool
pub unsafe fn canPlayFastForward(&self) -> bool
For releases of macOS prior to 10.9 and releases of iOS prior to 7.0, indicates whether the item can be played at rates greater than 1.0. Starting with macOS 10.9 and iOS 7.0, all AVPlayerItems with status AVPlayerItemReadyToPlay can be played at rates between 1.0 and 2.0, inclusive, even if canPlayFastForward is NO; for those releases canPlayFastForward indicates whether the item can be played at rates greater than 2.0.
Sourcepub unsafe fn canPlaySlowForward(&self) -> bool
pub unsafe fn canPlaySlowForward(&self) -> bool
Indicates whether the item can be played at rates between 0.0 and 1.0
Sourcepub unsafe fn canPlayReverse(&self) -> bool
pub unsafe fn canPlayReverse(&self) -> bool
Indicates whether the item can be played at rate -1.0
Sourcepub unsafe fn canPlaySlowReverse(&self) -> bool
pub unsafe fn canPlaySlowReverse(&self) -> bool
Indicates whether the item can be played at rates less between 0.0 and -1.0
Sourcepub unsafe fn canPlayFastReverse(&self) -> bool
pub unsafe fn canPlayFastReverse(&self) -> bool
Indicates whether the item can be played at rates less than -1.0
Sourcepub unsafe fn canStepForward(&self) -> bool
pub unsafe fn canStepForward(&self) -> bool
Indicates whether the item supports stepping forward; see -stepByCount:. Once the item has become ready to play, the value of canStepForward does not change even when boundary conditions are reached, such as when the item’s currentTime is its end time.
Sourcepub unsafe fn canStepBackward(&self) -> bool
pub unsafe fn canStepBackward(&self) -> bool
Indicates whether the item supports stepping backward; see -stepByCount:. Once the item has become ready to play, the value of canStepBackward does not change even when boundary conditions are reached, such as when the item’s currentTime is equal to kCMTimeZero.
Sourcepub unsafe fn configuredTimeOffsetFromLive(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn configuredTimeOffsetFromLive(&self) -> CMTime
objc2-core-media only.Indicates how close to the latest content in a live stream playback will begin after a live start or a seek to kCMTimePositiveInfinity.
For non-live assets this value is kCMTimeInvalid.
Sourcepub unsafe fn setConfiguredTimeOffsetFromLive(
&self,
configured_time_offset_from_live: CMTime,
)
Available on crate feature objc2-core-media only.
pub unsafe fn setConfiguredTimeOffsetFromLive( &self, configured_time_offset_from_live: CMTime, )
objc2-core-media only.Setter for configuredTimeOffsetFromLive.
Sourcepub unsafe fn recommendedTimeOffsetFromLive(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn recommendedTimeOffsetFromLive(&self) -> CMTime
objc2-core-media only.A recommended value for configuredTimeOffsetFromLive, based on observed network conditions.
For non-live assets this value is kCMTimeInvalid.
Sourcepub unsafe fn automaticallyPreservesTimeOffsetFromLive(&self) -> bool
pub unsafe fn automaticallyPreservesTimeOffsetFromLive(&self) -> bool
Indicates that after the player spends a period of time buffering media, it will skip forward if necessary to restore the playhead’s distance from the live edge of the presentation to what it was when buffering began.
If the value of this property is YES and the player must buffer media from the network in order to resume playback, the player will seek forward if necessary before resuming playback to restore the position that the playhead had when rebuffering began, relative to the end of the current AVPlayerItem’s seekableTimeRange.
This behavior applies to media buffering that occurs as a consequence of starting playback, seeking, and recovering from a playback stall.
Note that if the network cannot deliver media quickly enough to maintain the playback rate, playback may stall interminably.
This property value has no effect if the asset is not a live stream. The default value of this property is NO.
Sourcepub unsafe fn setAutomaticallyPreservesTimeOffsetFromLive(
&self,
automatically_preserves_time_offset_from_live: bool,
)
pub unsafe fn setAutomaticallyPreservesTimeOffsetFromLive( &self, automatically_preserves_time_offset_from_live: bool, )
Setter for automaticallyPreservesTimeOffsetFromLive.
Source§impl AVPlayerItem
AVPlayerItemTimeControl.
impl AVPlayerItem
AVPlayerItemTimeControl.
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 item.
Returns the current time of the item. Not key-value observable; use -[AVPlayer addPeriodicTimeObserverForInterval:queue:usingBlock:] instead.
- Returns: A CMTime
Sourcepub unsafe fn forwardPlaybackEndTime(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn forwardPlaybackEndTime(&self) -> CMTime
objc2-core-media only.The end time for forward playback.
Specifies the time at which playback should end when the playback rate is positive (see AVPlayer’s rate property). The default value is kCMTimeInvalid, which indicates that no end time for forward playback is specified. In this case, the effective end time for forward playback is the receiver’s duration.
When the end time is reached, the receiver will post AVPlayerItemDidPlayToEndTimeNotification and the AVPlayer will take the action indicated by the value of its actionAtItemEnd property (see AVPlayerActionAtItemEnd in AVPlayer.h).
The value of this property has no effect on playback when the rate is negative.
Sourcepub unsafe fn setForwardPlaybackEndTime(
&self,
forward_playback_end_time: CMTime,
)
Available on crate feature objc2-core-media only.
pub unsafe fn setForwardPlaybackEndTime( &self, forward_playback_end_time: CMTime, )
objc2-core-media only.Setter for forwardPlaybackEndTime.
Sourcepub unsafe fn reversePlaybackEndTime(&self) -> CMTime
Available on crate feature objc2-core-media only.
pub unsafe fn reversePlaybackEndTime(&self) -> CMTime
objc2-core-media only.The end time for reverse playback.
Specifies the time at which playback should end when the playback rate is negative (see AVPlayer’s rate property). The default value is kCMTimeInvalid, which indicates that no end time for reverse playback is specified. In this case, the effective end time for reverse playback is kCMTimeZero.
When the end time is reached, the receiver will post AVPlayerItemDidPlayToEndTimeNotification and the AVPlayer will take the action indicated by the value of its actionAtItemEnd property (see AVPlayerActionAtItemEnd in AVPlayer.h).
The value of this property has no effect on playback when the rate is positive.
Sourcepub unsafe fn setReversePlaybackEndTime(
&self,
reverse_playback_end_time: CMTime,
)
Available on crate feature objc2-core-media only.
pub unsafe fn setReversePlaybackEndTime( &self, reverse_playback_end_time: CMTime, )
objc2-core-media only.Setter for reversePlaybackEndTime.
Sourcepub unsafe fn seekableTimeRanges(&self) -> Retained<NSArray<NSValue>>
pub unsafe fn seekableTimeRanges(&self) -> Retained<NSArray<NSValue>>
This property provides a collection of time ranges that the player item can seek to. The ranges provided might be discontinous.
Returns an NSArray of NSValues containing CMTimeRanges.
Sourcepub unsafe fn seekToTime_completionHandler(
&self,
time: CMTime,
completion_handler: Option<&DynBlock<dyn Fn(Bool)>>,
)
Available on crate features block2 and objc2-core-media only.
pub unsafe fn seekToTime_completionHandler( &self, time: CMTime, completion_handler: Option<&DynBlock<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.
Use this method to seek to a specified time for the 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 the seek time is outside of seekable time ranges as indicated by seekableTimeRanges property, the seek request will be cancelled and the completion handler will be invoked with the finished parameter set to NO.
This method throws an exception if time is invalid or indefinite.
- Parameter time:
- Parameter completionHandler:
§Safety
completion_handler block must be sendable.
Sourcepub unsafe fn seekToTime_toleranceBefore_toleranceAfter_completionHandler(
&self,
time: CMTime,
tolerance_before: CMTime,
tolerance_after: CMTime,
completion_handler: Option<&DynBlock<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: Option<&DynBlock<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.
Use this method to seek to a specified time for the 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 the seek time is outside of seekable time ranges as indicated by seekableTimeRanges property, the seek request will be cancelled and the completion handler will be invoked with the finished parameter set to NO.
This method throws an exception if time is invalid or indefinite or if tolerance before or tolerance after is invalid or negative.
- Parameter time:
- Parameter toleranceBefore:
- Parameter toleranceAfter:
- Parameter completionHandler:
§Safety
completion_handler block must be sendable.
Sourcepub unsafe fn cancelPendingSeeks(&self)
pub unsafe fn cancelPendingSeeks(&self)
Cancel any pending seek requests and invoke the corresponding completion handlers if present.
Use this method to cancel and release the completion handlers of pending seeks. The finished parameter of the completion handlers will be set to NO.
Sourcepub unsafe fn currentDate(&self) -> Option<Retained<NSDate>>
pub unsafe fn currentDate(&self) -> Option<Retained<NSDate>>
If currentTime is mapped to a particular (real-time) date, return that date.
- Returns: Returns the date of current playback, or nil if playback is not mapped to any date.
Sourcepub unsafe fn seekToDate_completionHandler(
&self,
date: &NSDate,
completion_handler: Option<&DynBlock<dyn Fn(Bool)>>,
) -> bool
Available on crate feature block2 only.
pub unsafe fn seekToDate_completionHandler( &self, date: &NSDate, completion_handler: Option<&DynBlock<dyn Fn(Bool)>>, ) -> bool
block2 only.move playhead to a point corresponding to a particular date, and invokes the specified block when the seek operation has either been completed or been interrupted.
For playback content that is associated with a range of dates, move the playhead to point within that range and invokes the completion handler when the seek operation is complete. Will fail if the supplied date is outside the range or if the content is not associated with a range of dates. 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.
-
Parameter date: The new position for the playhead.
-
Parameter completionHandler: The block to invoke when seek operation is complete
-
Returns: Returns true if the playhead was moved to the supplied date.
§Safety
completion_handler block must be sendable.
Sourcepub unsafe fn stepByCount(&self, step_count: NSInteger)
pub unsafe fn stepByCount(&self, step_count: NSInteger)
Moves player’s current item’s current time forward or backward by the specified number of steps.
The size of each step depends on the enabled AVPlayerItemTracks of the AVPlayerItem.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
- Parameter stepCount: The number of steps by which to move. A positive number results in stepping forward, a negative number in stepping backward.
Sourcepub unsafe fn timebase(&self) -> Option<Retained<CMTimebase>>
Available on crate feature objc2-core-media only.
pub unsafe fn timebase(&self) -> Option<Retained<CMTimebase>>
objc2-core-media only.The item’s timebase.
You can examine the timebase to discover the relationship between the item’s time and the source clock used for drift synchronization. This timebase is read-only; you cannot set its time or rate to affect playback.
Source§impl AVPlayerItem
AVPlayerItemVisualPresentation.
impl AVPlayerItem
AVPlayerItemVisualPresentation.
Sourcepub unsafe fn videoComposition(&self) -> Option<Retained<AVVideoComposition>>
Available on crate feature AVVideoComposition only.
pub unsafe fn videoComposition(&self) -> Option<Retained<AVVideoComposition>>
AVVideoComposition only.Indicates the video composition settings to be applied during playback.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
This property throws an exception if a video composition is set with any of the following values:
- renderSize, renderScale, or frameDuration is less than or equal to zero
- sourceTrackIDForFrameTiming is less than or equal to zero
- uses AVVideoCompositionCoreAnimationTool (works for offline rendering only)
Sourcepub unsafe fn setVideoComposition(
&self,
video_composition: Option<&AVVideoComposition>,
)
Available on crate feature AVVideoComposition only.
pub unsafe fn setVideoComposition( &self, video_composition: Option<&AVVideoComposition>, )
AVVideoComposition only.Setter for videoComposition.
This is copied when set.
Sourcepub unsafe fn customVideoCompositor(
&self,
) -> Option<Retained<ProtocolObject<dyn AVVideoCompositing>>>
Available on crate feature AVVideoCompositing only.
pub unsafe fn customVideoCompositor( &self, ) -> Option<Retained<ProtocolObject<dyn AVVideoCompositing>>>
AVVideoCompositing only.Indicates the custom video compositor instance.
This property is nil if there is no video compositor, or if the internal video compositor is in use. This reference can be used to provide extra context to the custom video compositor instance if required. The value of this property can change as a result of setting the videoComposition property.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this property must be accessed on the main thread/queue.
Sourcepub unsafe fn seekingWaitsForVideoCompositionRendering(&self) -> bool
pub unsafe fn seekingWaitsForVideoCompositionRendering(&self) -> bool
Indicates whether the item’s timing follows the displayed video frame when seeking with a video composition
By default, item timing is updated as quickly as possible, not waiting for media at new times to be rendered when seeking or during normal playback. The latency that occurs, for example, between the completion of a seek operation and the display of a video frame at a new time is negligible in most situations. However, when video compositions are in use, the processing of video for any particular time may introduce noticeable latency. Therefore it may be desirable when a video composition is in use for the item’s timing be updated only after the video frame for a time has been displayed. This allows, for instance, an AVSynchronizedLayer associated with an AVPlayerItem to remain in synchronization with the displayed video and for the currentTime property to return the time of the displayed video.
This property has no effect on items for which videoComposition is nil.
Sourcepub unsafe fn setSeekingWaitsForVideoCompositionRendering(
&self,
seeking_waits_for_video_composition_rendering: bool,
)
pub unsafe fn setSeekingWaitsForVideoCompositionRendering( &self, seeking_waits_for_video_composition_rendering: bool, )
Setter for seekingWaitsForVideoCompositionRendering.
Sourcepub unsafe fn textStyleRules(
&self,
) -> Option<Retained<NSArray<AVTextStyleRule>>>
Available on crate feature AVTextStyleRule only.
pub unsafe fn textStyleRules( &self, ) -> Option<Retained<NSArray<AVTextStyleRule>>>
AVTextStyleRule only.An array of AVTextStyleRules representing text styling that can be applied to subtitles and other legible media.
The styling information contained in each AVTextStyleRule object in the array is used only when no equivalent styling information is provided by the media resource being played. For example, if the text style rules specify Courier font but the media resource specifies Helvetica font, the text will be drawn using Helvetica font.
This property has an effect only for tracks with media subtype kCMSubtitleFormatType_WebVTT.
Sourcepub unsafe fn setTextStyleRules(
&self,
text_style_rules: Option<&NSArray<AVTextStyleRule>>,
)
Available on crate feature AVTextStyleRule only.
pub unsafe fn setTextStyleRules( &self, text_style_rules: Option<&NSArray<AVTextStyleRule>>, )
AVTextStyleRule only.Setter for textStyleRules.
This is copied when set.
Sourcepub unsafe fn videoApertureMode(&self) -> Retained<AVVideoApertureMode>
Available on crate feature AVVideoSettings only.
pub unsafe fn videoApertureMode(&self) -> Retained<AVVideoApertureMode>
AVVideoSettings only.Specifies the video aperture mode to apply during playback.
See AVVideoApertureMode constants defined in AVVideoSettings.h. Default is AVVideoApertureModeCleanAperture.
Sourcepub unsafe fn setVideoApertureMode(
&self,
video_aperture_mode: &AVVideoApertureMode,
)
Available on crate feature AVVideoSettings only.
pub unsafe fn setVideoApertureMode( &self, video_aperture_mode: &AVVideoApertureMode, )
AVVideoSettings only.Setter for videoApertureMode.
This is copied when set.
Sourcepub unsafe fn appliesPerFrameHDRDisplayMetadata(&self) -> bool
pub unsafe fn appliesPerFrameHDRDisplayMetadata(&self) -> bool
Controls whether or not to apply the per frame HDR display metadata of the source during playback.
Sourcepub unsafe fn setAppliesPerFrameHDRDisplayMetadata(
&self,
applies_per_frame_hdr_display_metadata: bool,
)
pub unsafe fn setAppliesPerFrameHDRDisplayMetadata( &self, applies_per_frame_hdr_display_metadata: bool, )
Setter for appliesPerFrameHDRDisplayMetadata.
Source§impl AVPlayerItem
AVPlayerItemAudioProcessing.
impl AVPlayerItem
AVPlayerItemAudioProcessing.
Sourcepub unsafe fn audioTimePitchAlgorithm(
&self,
) -> Retained<AVAudioTimePitchAlgorithm>
Available on crate feature AVAudioProcessingSettings only.
pub unsafe fn audioTimePitchAlgorithm( &self, ) -> Retained<AVAudioTimePitchAlgorithm>
AVAudioProcessingSettings only.Indicates the processing algorithm used to manage audio pitch at varying rates and for scaled audio edits.
Constants for various time pitch algorithms, e.g. AVAudioTimePitchSpectral, are defined in AVAudioProcessingSettings.h. The default value for applications linked on or after iOS 15.0 or macOS 12.0 is AVAudioTimePitchAlgorithmTimeDomain. For iOS versions prior to 15.0 the default value is AVAudioTimePitchAlgorithmLowQualityZeroLatency. For macOS versions prior to 12.0 the default value is AVAudioTimePitchAlgorithmSpectral.
Sourcepub unsafe fn setAudioTimePitchAlgorithm(
&self,
audio_time_pitch_algorithm: &AVAudioTimePitchAlgorithm,
)
Available on crate feature AVAudioProcessingSettings only.
pub unsafe fn setAudioTimePitchAlgorithm( &self, audio_time_pitch_algorithm: &AVAudioTimePitchAlgorithm, )
AVAudioProcessingSettings only.Setter for audioTimePitchAlgorithm.
This is copied when set.
Sourcepub unsafe fn isAudioSpatializationAllowed(&self) -> bool
👎Deprecated: Use allowedAudioSpatializationFormats instead
pub unsafe fn isAudioSpatializationAllowed(&self) -> bool
Indicates whether audio spatialization is allowed
When audio spatialization is allowed for an AVPlayerItem, the AVPlayer may render multichannel audio if available even if the output device doesn’t support multichannel audio on its own, via use of a synthetic channel layout. When audio spatialization is not allowed, the AVPlayer must render audio with a channel layout that best matches the capabilities of the output device. This property is not observable. Defaults to YES.
Sourcepub unsafe fn setAudioSpatializationAllowed(
&self,
audio_spatialization_allowed: bool,
)
👎Deprecated: Use allowedAudioSpatializationFormats instead
pub unsafe fn setAudioSpatializationAllowed( &self, audio_spatialization_allowed: bool, )
Setter for isAudioSpatializationAllowed.
Sourcepub unsafe fn allowedAudioSpatializationFormats(
&self,
) -> AVAudioSpatializationFormats
Available on crate feature AVAudioProcessingSettings only.
pub unsafe fn allowedAudioSpatializationFormats( &self, ) -> AVAudioSpatializationFormats
AVAudioProcessingSettings only.Indicates the source audio channel layouts allowed by the receiver for spatialization.
Spatialization uses psychoacoustic methods to create a more immersive audio rendering when the content is played on specialized headphones and speaker arrangements. When an AVPlayerItem’s allowedAudioSpatializationFormats property is set to AVAudioSpatializationFormatMonoAndStereo the AVPlayer will attempt to spatialize content tagged with a stereo channel layout, two-channel content with no layout specified as well as mono. It is considered incorrect to render a binaural recording with spatialization. A binaural recording is captured using two carefully placed microphones at each ear where the intent, when played on headphones, is to reproduce a naturally occurring spatial effect. Content tagged with a binaural channel layout will ignore this property value. When an AVPlayerItem’s allowedAudioSpatializationFormats property is set to AVAudioSpatializationFormatMultichannel the AVPlayer will attempt to spatialize any decodable multichannel layout. Setting this property to AVAudioSpatializationFormatMonoStereoAndMultichannel indicates that the sender allows the AVPlayer to spatialize any decodable mono, stereo or multichannel layout. This property is not observable. The default value for this property with video content is AVAudioSpatializationFormatMonoStereoAndMultichannel. Otherwise, audio only content default value is AVAudioSpatializationFormatMultichannel.
Sourcepub unsafe fn setAllowedAudioSpatializationFormats(
&self,
allowed_audio_spatialization_formats: AVAudioSpatializationFormats,
)
Available on crate feature AVAudioProcessingSettings only.
pub unsafe fn setAllowedAudioSpatializationFormats( &self, allowed_audio_spatialization_formats: AVAudioSpatializationFormats, )
AVAudioProcessingSettings only.Setter for allowedAudioSpatializationFormats.
Sourcepub unsafe fn audioMix(&self) -> Option<Retained<AVAudioMix>>
Available on crate feature AVAudioMix only.
pub unsafe fn audioMix(&self) -> Option<Retained<AVAudioMix>>
AVAudioMix only.Indicates the audio mix parameters to be applied during playback
The inputParameters of the AVAudioMix must have trackIDs that correspond to a track of the receiver’s asset. Otherwise they will be ignored. (See AVAudioMix.h for the declaration of AVAudioMixInputParameters and AVPlayerItem’s asset property.)
Sourcepub unsafe fn setAudioMix(&self, audio_mix: Option<&AVAudioMix>)
Available on crate feature AVAudioMix only.
pub unsafe fn setAudioMix(&self, audio_mix: Option<&AVAudioMix>)
AVAudioMix only.Source§impl AVPlayerItem
AVPlayerItemPlayability.
impl AVPlayerItem
AVPlayerItemPlayability.
Sourcepub unsafe fn loadedTimeRanges(&self) -> Retained<NSArray<NSValue>>
pub unsafe fn loadedTimeRanges(&self) -> Retained<NSArray<NSValue>>
This property provides a collection of time ranges for which the player has the media data readily available. The ranges provided might be discontinuous.
Returns an NSArray of NSValues containing CMTimeRanges.
Sourcepub unsafe fn isPlaybackLikelyToKeepUp(&self) -> bool
pub unsafe fn isPlaybackLikelyToKeepUp(&self) -> bool
Indicates whether the item will likely play through without stalling.
This property communicates a prediction of playability. Factors considered in this prediction include I/O throughput and media decode performance. It is possible for playbackLikelyToKeepUp to indicate NO while the property playbackBufferFull indicates YES. In this event the playback buffer has reached capacity but there isn’t the statistical data to support a prediction that playback is likely to keep up. It is left to the application programmer to decide to continue media playback or not. See playbackBufferFull below.
Sourcepub unsafe fn isPlaybackBufferFull(&self) -> bool
pub unsafe fn isPlaybackBufferFull(&self) -> bool
Indicates that the internal media buffer is full and that further I/O is suspended.
This property reports that the data buffer used for playback has reach capacity. Despite the playback buffer reaching capacity there might not exist sufficient statistical data to support a playbackLikelyToKeepUp prediction of YES. See playbackLikelyToKeepUp above.
pub unsafe fn isPlaybackBufferEmpty(&self) -> bool
Sourcepub unsafe fn canUseNetworkResourcesForLiveStreamingWhilePaused(&self) -> bool
pub unsafe fn canUseNetworkResourcesForLiveStreamingWhilePaused(&self) -> bool
Indicates whether the player item can use network resources to keep playback state up to date while paused
For live streaming content, the player item may need to use extra networking and power resources to keep playback state up to date when paused. For example, when this property is set to YES, the seekableTimeRanges property will be periodically updated to reflect the current state of the live stream.
For clients linked on or after macOS 10.11 or iOS 9.0, the default value is NO. To minimize power usage, avoid setting this property to YES when you do not need playback state to stay up to date while paused.
Sourcepub unsafe fn setCanUseNetworkResourcesForLiveStreamingWhilePaused(
&self,
can_use_network_resources_for_live_streaming_while_paused: bool,
)
pub unsafe fn setCanUseNetworkResourcesForLiveStreamingWhilePaused( &self, can_use_network_resources_for_live_streaming_while_paused: bool, )
Sourcepub unsafe fn preferredForwardBufferDuration(&self) -> NSTimeInterval
pub unsafe fn preferredForwardBufferDuration(&self) -> NSTimeInterval
Indicates the media duration the caller prefers the player to buffer from the network ahead of the playhead to guard against playback disruption.
The value is in seconds. If it is set to 0, the player will choose an appropriate level of buffering for most use cases. Note that setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources. Note that the system may buffer less than the value of this property in order to manage resource consumption.
Sourcepub unsafe fn setPreferredForwardBufferDuration(
&self,
preferred_forward_buffer_duration: NSTimeInterval,
)
pub unsafe fn setPreferredForwardBufferDuration( &self, preferred_forward_buffer_duration: NSTimeInterval, )
Setter for preferredForwardBufferDuration.
Source§impl AVPlayerItem
AVPlayerItemVariantControl.
impl AVPlayerItem
AVPlayerItemVariantControl.
Sourcepub unsafe fn preferredPeakBitRate(&self) -> c_double
pub unsafe fn preferredPeakBitRate(&self) -> c_double
Indicates the desired limit of network bandwidth consumption for this item.
Set preferredPeakBitRate to non-zero to indicate that the player should attempt to limit item playback to that bit rate, expressed in bits per second.
If network bandwidth consumption cannot be lowered to meet the preferredPeakBitRate, it will be reduced as much as possible while continuing to play the item.
Sourcepub unsafe fn setPreferredPeakBitRate(&self, preferred_peak_bit_rate: c_double)
pub unsafe fn setPreferredPeakBitRate(&self, preferred_peak_bit_rate: c_double)
Setter for preferredPeakBitRate.
Sourcepub unsafe fn preferredPeakBitRateForExpensiveNetworks(&self) -> c_double
pub unsafe fn preferredPeakBitRateForExpensiveNetworks(&self) -> c_double
Indicates the desired limit of network bandwidth consumption for this item over expensive networks.
When preferredPeakBitRateForExpensiveNetworks is set to non-zero, the player will attempt to limit item playback to that bit rate when streaming over an expensive network, such as when using a cellular data plan. (See -[NWPath isExpensive])
If network bandwidth consumption cannot be lowered to meet the preferredPeakBitRateForExpensiveNetworks, it will be reduced as much as possible while continuing to play the item.
Note that preferredPeakBitRate still applies unconditionally. If preferredPeakBitRateForExpensiveNetworks is less restrictive (greater) than preferredPeakBitRate, preferredPeakBitRateForExpensiveNetworks has no practical effect.
Sourcepub unsafe fn setPreferredPeakBitRateForExpensiveNetworks(
&self,
preferred_peak_bit_rate_for_expensive_networks: c_double,
)
pub unsafe fn setPreferredPeakBitRateForExpensiveNetworks( &self, preferred_peak_bit_rate_for_expensive_networks: c_double, )
Setter for preferredPeakBitRateForExpensiveNetworks.
Sourcepub unsafe fn preferredMaximumResolution(&self) -> CGSize
Available on crate feature objc2-core-foundation only.
pub unsafe fn preferredMaximumResolution(&self) -> CGSize
objc2-core-foundation only.Indicates a preferred upper limit on the resolution of the video to be downloaded (or otherwise transferred) and rendered by the player.
The default value is CGSizeZero, which indicates that the client enforces no limit on video resolution. Other values indicate a preferred maximum video resolution. It only applies to HTTP Live Streaming asset.
Sourcepub unsafe fn setPreferredMaximumResolution(
&self,
preferred_maximum_resolution: CGSize,
)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setPreferredMaximumResolution( &self, preferred_maximum_resolution: CGSize, )
objc2-core-foundation only.Setter for preferredMaximumResolution.
Sourcepub unsafe fn preferredMaximumResolutionForExpensiveNetworks(&self) -> CGSize
Available on crate feature objc2-core-foundation only.
pub unsafe fn preferredMaximumResolutionForExpensiveNetworks(&self) -> CGSize
objc2-core-foundation only.Indicates a preferred upper limit on the resolution of the video to be downloaded that applies only when the download occurs over expensive networks.
The default value is CGSizeZero, which indicates that the client enforces no limit on video resolution. Other values indicate a preferred maximum video resolution. This limit applies only when streaming over an expensive network, such as when using a cellular data plan. (See -[NWPath isExpensive])
It only applies to HTTP Live Streaming asset.
Note that preferredMaximumResolution still applies unconditionally. If preferredMaximumResolutionForExpensiveNetworks is less restrictive (higher resolution) than preferredMaximumResolution, preferredMaximumResolutionForExpensiveNetworks has no practical effect.
Sourcepub unsafe fn setPreferredMaximumResolutionForExpensiveNetworks(
&self,
preferred_maximum_resolution_for_expensive_networks: CGSize,
)
Available on crate feature objc2-core-foundation only.
pub unsafe fn setPreferredMaximumResolutionForExpensiveNetworks( &self, preferred_maximum_resolution_for_expensive_networks: CGSize, )
objc2-core-foundation only.Setter for preferredMaximumResolutionForExpensiveNetworks.
Sourcepub unsafe fn startsOnFirstEligibleVariant(&self) -> bool
pub unsafe fn startsOnFirstEligibleVariant(&self) -> bool
Directs the player to start playback with the first eligible variant that appears in the stream’s master playlist.
This property influences AVPlayer’s algorithm for selecting which of the eligible variant streams in an HTTP Live Streaming master playlist is selected when playback first begins. In all cases, AVPlayer may switch to other variants during playback.
On releases prior to macOS 10.15, iOS 13, tvOS 13 and watchOS 6, AVPlayer starts HLS playback with the first eligible variant in the master playlist. On releases starting with macOS 10.15, iOS 13, tvOS 13 and watchOS 6, AVPlayer starts HLS playback by choosing an initial variant that optimizes the startup experience. On releases starting with macOS 11.0, iOS 14, tvOS 14 and watchOS 7, applications may set this property to YES to request that AVPlayer use the previous behaviour of using the first eligible variant in the master playlist. This would be appropriate, for example, for applications which wish to control initial variant selection by ordering the variants in the master playlist.
Note that changing this property may impact stream startup performance and quality. In order to be effective this property must be set before initial variant selection occurs. This property only applies to HTTP Live Streaming assets. The default value of this property is NO.
Sourcepub unsafe fn setStartsOnFirstEligibleVariant(
&self,
starts_on_first_eligible_variant: bool,
)
pub unsafe fn setStartsOnFirstEligibleVariant( &self, starts_on_first_eligible_variant: bool, )
Setter for startsOnFirstEligibleVariant.
Sourcepub unsafe fn variantPreferences(&self) -> AVVariantPreferences
pub unsafe fn variantPreferences(&self) -> AVVariantPreferences
Indicates preferences for variant switching.
Changing variant preferences during playback may result in a variant switch. The default value is AVVariantPreferenceNone.
Sourcepub unsafe fn setVariantPreferences(
&self,
variant_preferences: AVVariantPreferences,
)
pub unsafe fn setVariantPreferences( &self, variant_preferences: AVVariantPreferences, )
Setter for variantPreferences.
Source§impl AVPlayerItem
AVPlayerItemMediaSelection.
impl AVPlayerItem
AVPlayerItemMediaSelection.
Sourcepub unsafe fn selectMediaOption_inMediaSelectionGroup(
&self,
media_selection_option: Option<&AVMediaSelectionOption>,
media_selection_group: &AVMediaSelectionGroup,
)
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectMediaOption_inMediaSelectionGroup( &self, media_selection_option: Option<&AVMediaSelectionOption>, media_selection_group: &AVMediaSelectionGroup, )
AVMediaSelectionGroup only.Selects the media option described by the specified instance of AVMediaSelectionOption in the specified AVMediaSelectionGroup and deselects all other options in that group.
If the specified media selection option isn’t a member of the specified media selection group, no change in presentation state will result. If the value of the property allowsEmptySelection of the AVMediaSelectionGroup is YES, you can pass nil for mediaSelectionOption to deselect all media selection options in the group. Note that if multiple options within a group meet your criteria for selection according to locale or other considerations, and if these options are otherwise indistinguishable to you according to media characteristics that are meaningful for your application, content is typically authored so that the first available option that meets your criteria is appropriate for selection.
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
- Parameter mediaSelectionOption: The option to select.
- Parameter mediaSelectionGroup: The media selection group, obtained from the receiver’s asset, that contains the specified option.
Sourcepub unsafe fn selectMediaOptionAutomaticallyInMediaSelectionGroup(
&self,
media_selection_group: &AVMediaSelectionGroup,
)
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectMediaOptionAutomaticallyInMediaSelectionGroup( &self, media_selection_group: &AVMediaSelectionGroup, )
AVMediaSelectionGroup only.Selects the media option in the specified media selection group that best matches the AVPlayer’s current automatic selection criteria. Also allows automatic selection to be re-applied to the specified group subsequently if the relevant criteria are changed.
Has no effect unless the appliesMediaSelectionCriteriaAutomatically property of the associated AVPlayer is YES and unless automatic media selection has previously been overridden via -[AVPlayerItem selectMediaOption:inMediaSelectionGroup:].
Before macOS 13, iOS 16, tvOS 16, and watchOS 9, this method must be invoked on the main thread/queue.
- Parameter mediaSelectionGroup: The media selection group, obtained from the receiver’s asset, that contains the specified option.
Sourcepub unsafe fn currentMediaSelection(&self) -> Retained<AVMediaSelection>
Available on crate feature AVMediaSelection only.
pub unsafe fn currentMediaSelection(&self) -> Retained<AVMediaSelection>
AVMediaSelection only.Provides an instance of AVMediaSelection carrying current selections for each of the receiver’s media selection groups.
Source§impl AVPlayerItem
AVPlayerItemCustomMediaSelectionScheme.
impl AVPlayerItem
AVPlayerItemCustomMediaSelectionScheme.
Sourcepub unsafe fn preferredCustomMediaSelectionSchemes(
&self,
) -> Retained<NSArray<AVCustomMediaSelectionScheme>>
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn preferredCustomMediaSelectionSchemes( &self, ) -> Retained<NSArray<AVCustomMediaSelectionScheme>>
AVMediaSelectionGroup only.Indicates the AVCustomMediaSelectionSchemes of AVMediaSelectionGroups of the receiver’s asset with which an associated UI implementation should configure its interface for media selection.
Recommended usage: if use of a custom media selection scheme is desired, set this property before either replacing an AVPlayer’s current item with the receiver or adding the receiver to an AVQueuePlayer’s play queue. This will satisfy requirements of UI implementations that commit to a configuration of UI elements as the receiver becomes ready to play.
Sourcepub unsafe fn setPreferredCustomMediaSelectionSchemes(
&self,
preferred_custom_media_selection_schemes: &NSArray<AVCustomMediaSelectionScheme>,
)
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn setPreferredCustomMediaSelectionSchemes( &self, preferred_custom_media_selection_schemes: &NSArray<AVCustomMediaSelectionScheme>, )
AVMediaSelectionGroup only.Setter for preferredCustomMediaSelectionSchemes.
This is copied when set.
Sourcepub unsafe fn selectMediaPresentationLanguage_forMediaSelectionGroup(
&self,
language: &NSString,
media_selection_group: &AVMediaSelectionGroup,
)
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectMediaPresentationLanguage_forMediaSelectionGroup( &self, language: &NSString, media_selection_group: &AVMediaSelectionGroup, )
AVMediaSelectionGroup only.When the associated AVPlayer’s appliesMediaSelectionCriteriaAutomatically property is set to YES, configures the player item to prefer a particular language, replacing any previous preference for available languages of the specified group’s custom media selection scheme.
Overrides preferences for languages specified by the AVPlayer’s current media selection criteria. This method has no effect when the associated AVPlayer’s appliesMediaSelectionCriteriaAutomatically property has a value of NO, in which case you must use -selectMediaOption:inMediaSelectionGroup: instead in order to alter the presentation state of the media.
- Parameter languages: A BCP 47 language tag, typically obtained from the availableLanguages of the AVCustomMediaSelectionScheme of the specified AVMediaSelectionGroup.
- Parameter mediaSelectionGroup: The media selection group, obtained from the receiver’s asset, to which the specified setting is to be applied.
Sourcepub unsafe fn selectedMediaPresentationLanguageForMediaSelectionGroup(
&self,
media_selection_group: &AVMediaSelectionGroup,
) -> Option<Retained<NSString>>
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectedMediaPresentationLanguageForMediaSelectionGroup( &self, media_selection_group: &AVMediaSelectionGroup, ) -> Option<Retained<NSString>>
AVMediaSelectionGroup only.Returns the selected media presentation language for the specified media selection group, if any language has previously been selected via use of -selectMediaPresentationLanguages:forMediaSelectionGroup:.
- Parameter mediaSelectionGroup: The media selection group, obtained from the receiver’s asset, for which the selected media presentation language is requested.
Sourcepub unsafe fn selectMediaPresentationSetting_forMediaSelectionGroup(
&self,
media_presentation_setting: &AVMediaPresentationSetting,
media_selection_group: &AVMediaSelectionGroup,
)
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectMediaPresentationSetting_forMediaSelectionGroup( &self, media_presentation_setting: &AVMediaPresentationSetting, media_selection_group: &AVMediaSelectionGroup, )
AVMediaSelectionGroup only.When the associated AVPlayer’s appliesMediaSelectionCriteriaAutomatically property is set to YES, configures the player item to prefer a particular presentation setting, replacing any previous preference for settings of the same media presentation selector.
Note that preferences for media characteristics indicated by selected AVMediaPresentationSettings are treated as supplemental to the associated AVPlayer’s media selection criteria for the AVMediaSelectionGroup. An AVPlayer’s default media selection criteria can also indicate preferences for media characteristics, such as those indicating the availability of accessibility affordances such as audio descriptions, and these media characteristics can be left up to the AVPlayer to manage even when an AVCustomMediaSelectionScheme is in use. But if you wish to do so, you can use AVMediaPresentationSettings offered by a AVCustomMediaSelectionScheme in combination with custom AVPlayerMediaSelectionCriteria. If the specified setting isn’t offered by an AVMediaPresentationSelector of the AVCustomMediaSelectionScheme of the specified AVMediaSelectionGroup, no change in the presentation of the media will result. This method has no effect when the associated AVPlayer’s appliesMediaSelectionCriteriaAutomatically property has a value of NO, in which case you must use -selectMediaOption:inMediaSelectionGroup: instead in order to alter the presentation state of the media.
- Parameter mediaPresentationSetting: The setting to select.
- Parameter mediaSelectionGroup: The media selection group, obtained from the receiver’s asset, to which the specified setting is to be applied.
Sourcepub unsafe fn selectedMediaPresentationSettingsForMediaSelectionGroup(
&self,
media_selection_group: &AVMediaSelectionGroup,
) -> Retained<NSDictionary<AVMediaPresentationSelector, AnyObject>>
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectedMediaPresentationSettingsForMediaSelectionGroup( &self, media_selection_group: &AVMediaSelectionGroup, ) -> Retained<NSDictionary<AVMediaPresentationSelector, AnyObject>>
AVMediaSelectionGroup only.Indicates the media presentation settings that have most recently been selected for each AVMediaPresentationSelector of the AVCustomMediaSelectionScheme of the specified AVMediaSelectionGroup.
-
Parameter mediaSelectionGroup: An AVMediaSelectionGroup obtained from the receiver’s asset for which the currently selected media presentation settings are desired.
-
Returns: A dictionary with AVMediaPresentationSelectors as keys and AVMediaPresentationSettings as values, providing the most recently selected setting for each selector or, if no setting has previously been selected, NSNull.
Sourcepub unsafe fn effectiveMediaPresentationSettingsForMediaSelectionGroup(
&self,
media_selection_group: &AVMediaSelectionGroup,
) -> Retained<NSDictionary<AVMediaPresentationSelector, AnyObject>>
Available on crate feature AVMediaSelectionGroup only.
pub unsafe fn effectiveMediaPresentationSettingsForMediaSelectionGroup( &self, media_selection_group: &AVMediaSelectionGroup, ) -> Retained<NSDictionary<AVMediaPresentationSelector, AnyObject>>
AVMediaSelectionGroup only.Indicates the media presentation settings with media characteristics that are possessed by the currently selected AVMediaSelectionOption in the specified AVMediaSelectionGroup.
Effective media presentation settings can differ from the currently effective media presentation settings if no AVMediaSelectionOption of the specified AVMediaSelectionGroup with the currently selected media presentation language possesses all of the characteristics associated with the currently selected settings. A value of NSNull for an AVMediaPresentationSelector can occur if either the content is inappropriately authored for the use of the AVCustomMediaSelectionScheme or if the currently selected AVMediaSelectionOption has been selected by means other than through the use of AVMediaPresentationSettings.
-
Parameter mediaSelectionGroup: An AVMediaSelectionGroup obtained from the receiver’s asset for which the currently effective media presentation settings are desired.
-
Returns: A dictionary with AVMediaPresentationSelectors as keys and AVMediaPresentationSettings as values, unless the AVMediaSelectionOption currently selected in the group possesses none of the characteristics associated with the selector’s settings. In that case the dictionary value will be NSNull.
Source§impl AVPlayerItem
AVPlayerItemLogging.
impl AVPlayerItem
AVPlayerItemLogging.
Sourcepub unsafe fn accessLog(&self) -> Option<Retained<AVPlayerItemAccessLog>>
pub unsafe fn accessLog(&self) -> Option<Retained<AVPlayerItemAccessLog>>
Returns an object that represents a snapshot of the network access log. Can be nil.
An AVPlayerItemAccessLog provides methods to retrieve the network access log in a format suitable for serialization. If nil is returned then there is no logging information currently available for this AVPlayerItem. An AVPlayerItemNewAccessLogEntryNotification will be posted when new logging information becomes available. However, accessLog might already return a non-nil value even before the first notification is posted.
In certain situations, this method may temporarily block the calling thread during the ongoing log collection process. It is strongly recommended that the caller take appropriate measures to prevent blocking essential services such as the user interface, for example, by avoiding calling this method in the main thread.
- Returns: An autoreleased AVPlayerItemAccessLog instance.
Sourcepub unsafe fn errorLog(&self) -> Option<Retained<AVPlayerItemErrorLog>>
pub unsafe fn errorLog(&self) -> Option<Retained<AVPlayerItemErrorLog>>
Returns an object that represents a snapshot of the error log. Can be nil.
An AVPlayerItemErrorLog provides methods to retrieve the error log in a format suitable for serialization. If nil is returned then there is no logging information currently available for this AVPlayerItem.
In certain situations, this method may temporarily block the calling thread during the ongoing log collection process. It is strongly recommended that the caller take appropriate measures to prevent blocking essential services such as the user interface, for example, by avoiding calling this method in the main thread.
- Returns: An autoreleased AVPlayerItemErrorLog instance.
Source§impl AVPlayerItem
AVPlayerItemOutputs.
impl AVPlayerItem
AVPlayerItemOutputs.
Sourcepub unsafe fn addOutput(&self, output: &AVPlayerItemOutput)
Available on crate feature AVPlayerItemOutput only.
pub unsafe fn addOutput(&self, output: &AVPlayerItemOutput)
AVPlayerItemOutput only.Adds the specified instance of AVPlayerItemOutput to the receiver’s collection of outputs.
The class of AVPlayerItemOutput provided dictates the data structure that decoded samples are vended in.
When an AVPlayerItemOutput is associated with an AVPlayerItem, samples are provided for a media type in accordance with the rules for mixing, composition, or exclusion that the AVPlayer honors among multiple enabled tracks of that media type for its own rendering purposes. For example, video media will be composed according to the instructions provided via AVPlayerItem.videoComposition, if present. Audio media will be mixed according to the parameters provided via AVPlayerItem.audioMix, if present.
- Parameter output: An instance of AVPlayerItemOutput
Sourcepub unsafe fn removeOutput(&self, output: &AVPlayerItemOutput)
Available on crate feature AVPlayerItemOutput only.
pub unsafe fn removeOutput(&self, output: &AVPlayerItemOutput)
AVPlayerItemOutput only.Removes the specified instance of AVPlayerItemOutput from the receiver’s collection of outputs.
- Parameter output: An instance of AVPlayerItemOutput
Sourcepub unsafe fn outputs(&self) -> Retained<NSArray<AVPlayerItemOutput>>
Available on crate feature AVPlayerItemOutput only.
pub unsafe fn outputs(&self) -> Retained<NSArray<AVPlayerItemOutput>>
AVPlayerItemOutput only.The collection of associated outputs.
Source§impl AVPlayerItem
AVPlayerItemMediaDataCollectors.
impl AVPlayerItem
AVPlayerItemMediaDataCollectors.
Sourcepub unsafe fn addMediaDataCollector(
&self,
collector: &AVPlayerItemMediaDataCollector,
)
Available on crate feature AVPlayerItemMediaDataCollector only.
pub unsafe fn addMediaDataCollector( &self, collector: &AVPlayerItemMediaDataCollector, )
AVPlayerItemMediaDataCollector only.Adds the specified instance of AVPlayerItemMediaDataCollector to the receiver’s collection of mediaDataCollectors.
This method may incur additional I/O to collect the requested media data asynchronously.
- Parameter collector: An instance of AVPlayerItemMediaDataCollector
Sourcepub unsafe fn removeMediaDataCollector(
&self,
collector: &AVPlayerItemMediaDataCollector,
)
Available on crate feature AVPlayerItemMediaDataCollector only.
pub unsafe fn removeMediaDataCollector( &self, collector: &AVPlayerItemMediaDataCollector, )
AVPlayerItemMediaDataCollector only.Removes the specified instance of AVPlayerItemMediaDataCollector from the receiver’s collection of mediaDataCollectors.
- Parameter collector: An instance of AVPlayerItemMediaDataCollector
Sourcepub unsafe fn mediaDataCollectors(
&self,
) -> Retained<NSArray<AVPlayerItemMediaDataCollector>>
Available on crate feature AVPlayerItemMediaDataCollector only.
pub unsafe fn mediaDataCollectors( &self, ) -> Retained<NSArray<AVPlayerItemMediaDataCollector>>
AVPlayerItemMediaDataCollector only.The collection of associated mediaDataCollectors.
Source§impl AVPlayerItem
AVPlayerItemDeprecated.
impl AVPlayerItem
AVPlayerItemDeprecated.
Sourcepub unsafe fn seekToTime(&self, time: CMTime)
👎Deprecated: Use -seekToTime:completionHandler:, passing nil for the completionHandler if you don’t require notification of completionAvailable on crate feature objc2-core-media only.
pub unsafe fn seekToTime(&self, time: CMTime)
objc2-core-media only.Moves the playback cursor.
Use this method to seek to a specified time for the item. The time seeked to may differ from the specified time for efficiency. For sample accurate seeking see seekToTime:toleranceBefore:toleranceAfter:. If the seek time is outside of seekable time ranges as indicated by seekableTimeRanges property, the seek request will be cancelled.
- Parameter time:
Sourcepub unsafe fn seekToTime_toleranceBefore_toleranceAfter(
&self,
time: CMTime,
tolerance_before: CMTime,
tolerance_after: CMTime,
)
👎Deprecated: Use -seekToTime:toleranceBefore:toleranceAfter:completionHandler:, passing nil for the completionHandler if you don’t require notification of completionAvailable 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.
Use this method to seek to a specified time for the 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. Seeking is constrained by the collection of seekable time ranges. If you seek to a time outside all of the seekable ranges the seek will result in a currentTime within the seekable ranges. If the seek time is outside of seekable time ranges as indicated by seekableTimeRanges property, the seek request will be cancelled.
- Parameter time:
- Parameter toleranceBefore:
- Parameter toleranceAfter:
Sourcepub unsafe fn seekToDate(&self, date: &NSDate) -> bool
👎Deprecated: Use -seekToDate:completionHandler:, passing nil for the completionHandler if you don’t require notification of completion
pub unsafe fn seekToDate(&self, date: &NSDate) -> bool
move playhead to a point corresponding to a particular date.
For playback content that is associated with a range of dates, move the playhead to point within that range. Will fail if the supplied date is outside the range or if the content is not associated with a range of dates.
-
Parameter date: The new position for the playhead.
-
Returns: Returns true if the playhead was moved to the supplied date.
Sourcepub unsafe fn selectedMediaOptionInMediaSelectionGroup(
&self,
media_selection_group: &AVMediaSelectionGroup,
) -> Option<Retained<AVMediaSelectionOption>>
👎Deprecated: Use currentMediaSelection to obtain an instance of AVMediaSelection, which encompasses the currently selected AVMediaSelectionOption in each of the available AVMediaSelectionGroupsAvailable on crate feature AVMediaSelectionGroup only.
pub unsafe fn selectedMediaOptionInMediaSelectionGroup( &self, media_selection_group: &AVMediaSelectionGroup, ) -> Option<Retained<AVMediaSelectionOption>>
AVMediaSelectionGroup only.Indicates the media selection option that’s currently selected from the specified group. May be nil.
If the value of the property allowsEmptySelection of the AVMediaSelectionGroup is YES, the currently selected option in the group may be nil.
-
Parameter mediaSelectionGroup: A media selection group obtained from the receiver’s asset.
-
Returns: An instance of AVMediaSelectionOption that describes the currently selection option in the group.
impl AVPlayerItem
AVMetricEventStreamPublisher.
Source§impl AVPlayerItem
AVPlayerItemIntegratedTimelineSupport.
impl AVPlayerItem
AVPlayerItemIntegratedTimelineSupport.
Sourcepub unsafe fn integratedTimeline(
&self,
) -> Retained<AVPlayerItemIntegratedTimeline>
Available on crate feature AVPlayerItemIntegratedTimeline only.
pub unsafe fn integratedTimeline( &self, ) -> Retained<AVPlayerItemIntegratedTimeline>
AVPlayerItemIntegratedTimeline only.Obtain an instance of AVPlayerItemIntegratedTimeline representing the timing and control of playback of the item with its scheduled AVPlayerInterstitialEvents. This value will return nil for AVPlayerItems in an interstitial player.
Source§impl AVPlayerItem
AVPlayerItemProtectedContent.
impl AVPlayerItem
AVPlayerItemProtectedContent.
Methods supporting protected content.
Sourcepub unsafe fn isAuthorizationRequiredForPlayback(&self) -> bool
Available on crate feature AVPlayerItemProtectedContentAdditions only.
pub unsafe fn isAuthorizationRequiredForPlayback(&self) -> bool
AVPlayerItemProtectedContentAdditions only.Indicates whether or not authorization is required to play the content.
This property reports whether or not authorization is required for the receiver’s content to be played. If it does not require authorization, then none of the other methods or properties in the AVPlayerItemProtectedContent category apply (though they will return sensible values where possible). This value is NOT key-value observable.
Sourcepub unsafe fn isApplicationAuthorizedForPlayback(&self) -> bool
Available on crate feature AVPlayerItemProtectedContentAdditions only.
pub unsafe fn isApplicationAuthorizedForPlayback(&self) -> bool
AVPlayerItemProtectedContentAdditions only.Indicates whether the calling application can be used to play the content.
This property reports whether or not the calling application is authorized to play the content associated with the receiver. Note that application authorization is independent of content authorization (see contentAuthorizedForPlayback) and that both must be granted in order for an application to be allowed to play protected content. Also, unlike content authorization, application authorization is not dependent on user credentials (i.e. if applicationAuthorizedForPlayback is NO, there are no means to obtain authorization). This value is NOT key-value observable.
Sourcepub unsafe fn isContentAuthorizedForPlayback(&self) -> bool
Available on crate feature AVPlayerItemProtectedContentAdditions only.
pub unsafe fn isContentAuthorizedForPlayback(&self) -> bool
AVPlayerItemProtectedContentAdditions only.Indicates whether the content has been authorized by the user (e.g. by authorizing the content’s associated account in iTunes).
This property reports whether or not the user has provided the necessary credentials to the system in order for the content to be decrypted for playback. Note that content authorization is independent of application authorization (see applicationAuthorizedForPlayback) and that both must be granted in order for an application to be allowed to play protected content. This value is NOT key-value observable.
Sourcepub unsafe fn requestContentAuthorizationAsynchronouslyWithTimeoutInterval_completionHandler(
&self,
timeout_interval: NSTimeInterval,
handler: &DynBlock<dyn Fn()>,
)
Available on crate features AVPlayerItemProtectedContentAdditions and block2 only.
pub unsafe fn requestContentAuthorizationAsynchronouslyWithTimeoutInterval_completionHandler( &self, timeout_interval: NSTimeInterval, handler: &DynBlock<dyn Fn()>, )
AVPlayerItemProtectedContentAdditions and block2 only.Causes appropriate action to be taken to allow the user to authorize the content for playback.
Calling this method will present the user with the opportunity to authorize the content (e.g. by launching iTunes and prompting the user to enter their Apple ID and password). When the user has taken action (or the timeout has elapsted), the completion handler will be invoked. The status of the authorization attempt can be determined by checking the value of the contentAuthorizationRequestStatus property. Note that even if the status indicates a completed authorization, the content may still not be authorized (e.g. if the user authorizes an Apple ID other than that associated with the content). The contentAuthorizedForPlayback property should be re-checked to verify whether the content has actually been authorized before continuing. It is not necessary to call this method if the value of contentAuthorizedForPlayback is already true.
Parameter timeoutInterval: The maximum amount of time to wait for the user to authorize the content in seconds before calling the handler block with a timeout result.
Parameter handler: Block to be called upon completion.
§Safety
handler block must be sendable.
Sourcepub unsafe fn cancelContentAuthorizationRequest(&self)
Available on crate feature AVPlayerItemProtectedContentAdditions only.
pub unsafe fn cancelContentAuthorizationRequest(&self)
AVPlayerItemProtectedContentAdditions only.Causes the currently outstanding content authorization request to be cancelled.
Calling this method while a content authorization request is pending will cause that request to be cancelled and its completion handler to be invoked with a status of AVContentAuthorizationCancelled. This call does not block.
Sourcepub unsafe fn contentAuthorizationRequestStatus(
&self,
) -> AVContentAuthorizationStatus
Available on crate feature AVPlayerItemProtectedContentAdditions only.
pub unsafe fn contentAuthorizationRequestStatus( &self, ) -> AVContentAuthorizationStatus
AVPlayerItemProtectedContentAdditions only.Indicates the status of the most recent call to requestContentAuthorizationAsynchronouslyWithTimeoutInterval:CompletionHandler:
This property reports the authorization status as determined by the most recent call to requestContentAuthorizationAsynchronouslyWithTimeoutInterval:CompletionHandler:. The value will be AVContentAuthorizationUnknown before the first call and between the time a request call is made and just prior to the completion handler being executed (i.e. it is safe to query this property from the completion handler). This value is NOT key-value observable.
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.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§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<AVPlayerItem> for AVPlayerItem
impl AsRef<AVPlayerItem> for AVPlayerItem
Source§impl AsRef<AnyObject> for AVPlayerItem
impl AsRef<AnyObject> for AVPlayerItem
Source§impl AsRef<NSObject> for AVPlayerItem
impl AsRef<NSObject> for AVPlayerItem
Source§impl Borrow<AnyObject> for AVPlayerItem
impl Borrow<AnyObject> for AVPlayerItem
Source§impl Borrow<NSObject> for AVPlayerItem
impl Borrow<NSObject> for AVPlayerItem
Source§impl ClassType for AVPlayerItem
impl ClassType for AVPlayerItem
Source§const NAME: &'static str = "AVPlayerItem"
const NAME: &'static str = "AVPlayerItem"
Source§type ThreadKind = dyn MainThreadOnly
type ThreadKind = dyn MainThreadOnly
Source§impl CopyingHelper for AVPlayerItem
impl CopyingHelper for AVPlayerItem
Source§type Result = AVPlayerItem
type Result = AVPlayerItem
Self if the type has no
immutable counterpart. Read moreSource§impl Debug for AVPlayerItem
impl Debug for AVPlayerItem
Source§impl Deref for AVPlayerItem
impl Deref for AVPlayerItem
Source§impl Hash for AVPlayerItem
impl Hash for AVPlayerItem
Source§impl Message for AVPlayerItem
impl Message for AVPlayerItem
Source§impl NSCopying for AVPlayerItem
impl NSCopying for AVPlayerItem
Source§impl NSObjectProtocol for AVPlayerItem
impl NSObjectProtocol for AVPlayerItem
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 PartialEq for AVPlayerItem
impl PartialEq for AVPlayerItem
Source§impl RefEncode for AVPlayerItem
impl RefEncode for AVPlayerItem
Source§const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
const ENCODING_REF: Encoding = <NSObject as ::objc2::RefEncode>::ENCODING_REF
impl AVMetricEventStreamPublisher for AVPlayerItem
impl DowncastTarget for AVPlayerItem
impl Eq for AVPlayerItem
Auto Trait Implementations§
impl !Freeze for AVPlayerItem
impl !RefUnwindSafe for AVPlayerItem
impl !Send for AVPlayerItem
impl !Sync for AVPlayerItem
impl !Unpin for AVPlayerItem
impl !UnwindSafe for AVPlayerItem
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