Class: AVPlayer
Overview
You use an AVPlayer object to implement controllers and user interfaces for single- or multiple-item playback. The multiple-item case supports advanced behaviors.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- actionAtItemEnd
The action to perform when an item has finished playing.
-
- closedCaptionDisplayEnabled
Indicates whether the player uses closed captioning.
-
- currentItem
readonly
The player’s current item.
-
- error
readonly
If the receiver’s status is AVPlayerStatusFailed, this describes the error that caused the failure.
-
- masterClock
The master clock used for item timebases.
-
- outputObscuredDueToInsufficientExternalProtection
readonly
A Boolean value indicating whether output is being obscured because of insufficient external protection.
-
- rate
The current rate of playback.
-
- status
readonly
Indicates whether the player can be used for playback.
Class Method Summary (collapse)
-
+ playerWithPlayerItem:
Returns a new player initialized to play a given single audiovisual item You can use this method to play items for which an AVAsset object has previously been created (see initWithAsset: in AVPlayerItem).
-
+ playerWithURL:
Returns a new player to play a single audiovisual resource referenced by a given URL.
Instance Method Summary (collapse)
-
- addBoundaryTimeObserverForTimes:queue:usingBlock:
Requests invocation of a block when specified times are traversed during normal playback.
-
- addPeriodicTimeObserverForInterval:queue:usingBlock:
Requests invocation of a given block during playback to report changing time.
-
- cancelPendingPrerolls
Cancels the preloading of media data.
-
- currentTime
Returns the current time of the current item.
-
- initWithPlayerItem:
Initializes a new player to play a given single audiovisual item.
-
- initWithURL:
Initializes a new player to play a single audiovisual resource referenced by a given URL.
-
- pause
Pauses playback.
-
- play
Begins playback of the current item.
-
- prerollAtRate:completionHandler:
Begins loading media data to prime the media pipelines for playback.
-
- removeTimeObserver:
Cancels a previously registered time observer.
-
- replaceCurrentItemWithPlayerItem:
Replaces the player item with a new player item.
-
- seekToDate:
Moves the playback cursor to the time specified by a date object.
-
- seekToDate:completionHandler:
Moves the playback cursor to the specified time and executes the specified block when the seek operation completes or is interrupted.
-
- seekToTime:
Moves the playback cursor to a given time.
-
- seekToTime:completionHandler:
Moves the playback cursor and executes the specified block when the seek operation has either been completed or been interrupted.
-
- seekToTime:toleranceBefore:toleranceAfter:
Moves the playback cursor within a specified time bound.
-
- seekToTime:toleranceBefore:toleranceAfter:completionHandler:
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.
-
- setRate:time:atHostTime:
Synchronizes the playback rate and time of the current item with an external source.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Attribute Details
- (AVPlayerActionAtItemEnd) actionAtItemEnd
The action to perform when an item has finished playing. For possible values, see “AVPlayerActionAtItemEnd.”
- (Boolean) closedCaptionDisplayEnabled
Indicates whether the player uses closed captioning.
- (AVPlayerItem) currentItem (readonly)
The player’s current item. (read-only)
- (NSError) error (readonly)
If the receiver’s status is AVPlayerStatusFailed, this describes the error that caused the failure. (read-only) The value of this property is an error object 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.
- (__attribute__((NSObject)) CMClockRef) masterClock
The master clock used for item timebases. The default value of this property is NULL, which means that the master clock is automatically chosen. When non-NULL, this property overrides the automatic choice of master clock for item timebases. This is most useful when you are synchronizing video-only movies with audio played by another source.Important: If you specify a master clock other than the appropriate audio device’s clock, the audio may drift out of sync.
- (Boolean) outputObscuredDueToInsufficientExternalProtection (readonly)
A Boolean value indicating whether output is being obscured because of insufficient external protection. (read-only) Items that incorporate copy protection or other forms of security might have their visual content obscured by the player object if the current device configuration does not meet the requirements for protecting the item. This property reports whether the player is currently obscuring the item. If the current item does not require external protection or if the device configuration sufficiently protects the item, the value of this property is set to NO.You can use this property to determine whether to change your app’s user interface to reflect the change in visibility. You can observe changes to the value of this property using key-value observing.
- (Float) rate
The current rate of playback. 0.0 means “stopped”, 1.0 means “play at the natural rate of the current item”.
- (AVPlayerStatus) status (readonly)
Indicates whether the player can be used for playback. (read-only) When the value of this property is AVPlayerStatusFailed, you can no longer use the player for playback and you need to create a new instance to replace it. If this happens, you can check the value of the error property to determine the nature of the failure.This property is key value observable using key-value observing.
Class Method Details
+ (Object) playerWithPlayerItem(item)
Returns a new player initialized to play a given single audiovisual item You can use this method to play items for which an AVAsset object has previously been created (see initWithAsset: in AVPlayerItem).
+ (Object) playerWithURL(URL)
Returns a new player to play a single audiovisual resource referenced by a given URL. This method implicitly creates an AVPlayerItem object. You can get the player item using currentItem.
Instance Method Details
- (Object) addBoundaryTimeObserverForTimes(times, queue:queue, usingBlock:block)
Requests invocation of a block when specified times are traversed during normal playback. You must retain the returned value as long as you want the time observer to be invoked by the player. Each invocation of this method should be paired with a corresponding call to removeTimeObserver:.
- (Object) addPeriodicTimeObserverForInterval(interval, queue:queue, usingBlock:block)
Requests invocation of a given block during playback to report changing time. You must retain the returned value as long as you want the time observer to be invoked by the player. Each invocation of this method should be paired with a corresponding call to removeTimeObserver:.The block is invoked periodically at the interval specified, interpreted according to the timeline of the current item. The block is also invoked whenever time jumps and whenever playback starts or stops. If the interval corresponds to a very short interval in real time, the player may invoke the block less frequently than requested. Even so, the player will invoke the block sufficiently often for the client to update indications of the current time appropriately in its end-user interface.
- (Object) cancelPendingPrerolls
Cancels the preloading of media data. This method cancels any pending operations to prepare the render pipeline for the current item.
- (CMTime) currentTime
Returns the current time of the current item. This property is not key-value observable; use addPeriodicTimeObserverForInterval:queue:usingBlock: or addBoundaryTimeObserverForTimes:queue:usingBlock: instead.
- (Object) initWithPlayerItem(item)
Initializes a new player to play a given single audiovisual item. You can use this method to play items for which you have an existing AVAsset object (see initWithAsset: in AVPlayerItem).
- (Object) initWithURL(URL)
Initializes a new player to play a single audiovisual resource referenced by a given URL. This method implicitly creates an AVPlayerItem object. You can get the player item using currentItem.
- (Object) pause
Pauses playback. This is the same as setting rate to 0.0.
- (Object) play
Begins playback of the current item. This is the same as setting rate to 1.0.
- (Object) prerollAtRate(rate, completionHandler:completionHandler)
Begins loading media data to prime the media pipelines for playback. This method loads data starting at the item’s current playback time. The current rate for the playback item should always be 0 prior to calling this method. After the method calls the completion handler, you can change the item’s playback rate to begin playback.If the player object is not ready to play (its status property is not AVPlayerStatusReadyToPlay), this method throws an exception.
- (Object) removeTimeObserver(observer)
Cancels a previously registered time observer. 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.You should use this method to explicitly cancel each time observer added using addPeriodicTimeObserverForInterval:queue:usingBlock: and addBoundaryTimeObserverForTimes:queue:usingBlock:.
- (Object) replaceCurrentItemWithPlayerItem(item)
Replaces the player item with a new player item. You can only use this method with players created without queues. If the player was not initialized with a single item and no queue, the method throws an exception.The item replacement occurs asynchronously; observe the currentItem property to find out when the replacement will/did occur.
- (Object) seekToDate(date)
Moves the playback cursor to the time specified by a date object.
- (Object) seekToDate(date, completionHandler:completionHandler)
Moves the playback cursor to the specified time and executes the specified block when the seek operation completes or is interrupted. Use this method to seek to a specified time for the current player item and be notified when the operation completes. If the seek request completes without being interrupted (either by another seek request or by any other operation), the completion handler you provide is executed with the finished parameter set to YES. If another seek request is already in progress when you call this method, the completion handler for the in-progress seek request is executed immediately with the finished parameter set to NO.
- (Object) seekToTime(time)
Moves the playback cursor to a given time. The time seeked to may differ from the specified time for efficiency. For sample accurate seeking see seekToTime:toleranceBefore:toleranceAfter:.
- (Object) seekToTime(time, completionHandler:completionHandler)
Moves the playback cursor and executes 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 current player item and be notified when the operation completes. If the seek request completes without being interrupted (either by another seek request or by any other operation), the completion handler you provide is executed with the finished parameter set to YES. If another seek request is already in progress when you call this method, the completion handler for the in-progress seek request is executed immediately with the finished parameter set to NO.
- (Object) seekToTime(time, toleranceBefore:toleranceBefore, toleranceAfter:toleranceAfter)
Moves the playback cursor within a specified time bound. The time seeked to will be within the range [time-beforeTolerance, time+afterTolerance], and may differ from the specified time for efficiency. If you pass kCMTimeZero for both toleranceBefore and toleranceAfter (to request sample accurate seeking), you may incur additional decoding delay.Passing kCMTimePositiveInfinity for both toleranceBefore and toleranceAfter is the same as messaging seekToTime: directly.
- (Object) seekToTime(time, toleranceBefore:toleranceBefore, toleranceAfter:toleranceAfter, completionHandler:completionHandler)
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 current player item and to be notified when the seek operation is complete.The time seeked to will be within the range [time-beforeTolerance, time+afterTolerance], and may differ from the specified time for efficiency. If you pass kCMTimeZero for both toleranceBefore and toleranceAfter (to request sample accurate seeking), you may incur additional decoding delay.Invoking this method with toleranceBefore set to kCMTimePositiveInfinity and toleranceAfter set to kCMTimePositiveInfinity is the same as invoking seekToTime:.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.
- (Object) setRate(rate, time:itemTime, atHostTime:hostClockTime)
Synchronizes the playback rate and time of the current item with an external source. This method adjusts the current item’s timebase so that the time in itemTime is in sync with the time in hostClockTime. Thus, if hostClockTime specifies a time in the past, the item’s timebase is adjusted to make it appear as if the item has been running at the specified rate since itemTime. And if hostClockTime specifies a time in the future, playback is adjusted backward (if possible) so that the value in itemTime occurs at the precise moment the host’s clock reaches the value in hostClockTime. If there is no content to play before the time specified by itemTime, playback holds until the two times come into sync.This method does not ensure that media data is loaded before the timebase starts moving. However, if you specify a host time in the near future, that would give you some time to load the media data and prepare for playback.