Class: AVPlayer

Inherits:
NSObject show all

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

AVQueuePlayer

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

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.”

Returns:

  • (AVPlayerActionAtItemEnd)

- (Boolean) closedCaptionDisplayEnabled

Indicates whether the player uses closed captioning.

Returns:

  • (Boolean)

- (AVPlayerItem) currentItem (readonly)

The player’s current item. (read-only)

Returns:

- (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.

Returns:

- (__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.

Returns:

  • (__attribute__((NSObject)) CMClockRef)

- (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.

Returns:

  • (Boolean)

- (Float) rate

The current rate of playback. 0.0 means “stopped”, 1.0 means “play at the natural rate of the current item”.

Returns:

- (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.

Returns:

  • (AVPlayerStatus)

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).

Parameters:

Returns:

  • (Object)

    A new player, initialized to play item.

+ (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.

Parameters:

  • URL (NSURL)

    An URL that identifies an audiovisual resource.

Returns:

  • (Object)

    A new player initialized to play the audiovisual resource specified by URL.

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:.

Parameters:

  • times

    An array of NSValue objects containing CMTime values representing the times at which to invoke block.

  • queue

    A serial queue onto which block should be enqueued. If you pass NULL, the main queue (obtained using dispatch_get_main_queue(3) OS X Developer Tools Manual Page) is used. Passing a concurrent queue will result in undefined behavior.

  • block

    The block to be invoked when any of the times in times is crossed during normal playback.

Returns:

  • (Object)

    An opaque object that you pass as the argument to removeTimeObserver: to stop observation.

- (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.

Parameters:

  • interval (CMTime)

    The interval of invocation of the block during normal playback, according to progress of the current time of the player.

  • queue (dispatch_queue_t)

    A serial queue onto which block should be enqueued. If you pass NULL, the main queue (obtained using dispatch_get_main_queue(3) OS X Developer Tools Manual Page) is used. Passing a concurrent queue will result in undefined behavior.

  • block (Object)

    The block to be invoked periodically.The block takes a single parameter:timeThe time at which the block is invoked.

  • time (CMTime time)

    The time at which the block is invoked.

Returns:

  • (Object)

    An opaque object that you pass as the argument to removeTimeObserver: to cancel observation.

- (Object) cancelPendingPrerolls

Cancels the preloading of media data. This method cancels any pending operations to prepare the render pipeline for the current item.

Returns:

- (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.

Returns:

  • (CMTime)

    The current time of the current item.

- (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).

Parameters:

Returns:

  • (Object)

    The receiver, initialized to play item.

- (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.

Parameters:

  • URL (NSURL)

    An URL that identifies an audiovisual resource.

Returns:

  • (Object)

    The receiver, initialized to play the audiovisual resource specified by URL.

- (Object) pause

Pauses playback. This is the same as setting rate to 0.0.

Returns:

- (Object) play

Begins playback of the current item. This is the same as setting rate to 1.0.

Returns:

- (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.

Parameters:

  • rate

    The playback rate to use when determining how much data to load.

  • completionHandler

    A block to execute when the player finishes the load attempt. This block takes a single Boolean parameter that contains YES if the data was loaded or NO if there was a problem. For example, the value might be NO if the preroll was interrupted by a time change or incompatible rate change.

Returns:

- (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:.

Parameters:

  • observer (Object)

    An object returned by a previous call to addPeriodicTimeObserverForInterval:queue:usingBlock: or addBoundaryTimeObserverForTimes:queue:usingBlock:.

Returns:

- (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.

Parameters:

Returns:

- (Object) seekToDate(date)

Moves the playback cursor to the time specified by a date object.

Parameters:

  • date (NSDate)

    The time at which to move the playback cursor.

Returns:

- (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.

Parameters:

  • date (NSDate)

    The time to which to move the playback cursor.

  • completionHandler (Object)

    The block to invoke when the seek operation has either been completed or been interrupted. The block takes one argument:finishedIndicates whether the seek operation completed.

  • finished (BOOL finished)

    Indicates whether the seek operation completed.

Returns:

- (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:.

Parameters:

  • time (CMTime)

    The time to which to move the playback cursor.

Returns:

- (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.

Parameters:

  • time (CMTime)

    The time to which you would like to move the playback cursor.

  • completionHandler (Object)

    The block to invoke when the seek operation has either been completed or been interrupted. The block takes one argument:finishedIndicates whether the seek operation completed.

  • finished (BOOL finished)

    Indicates whether the seek operation completed.

Returns:

- (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.

Parameters:

  • time (CMTime)

    The time to which you would like to move the playback cursor.

  • toleranceBefore (CMTime)

    The tolerance allowed before time.

  • toleranceAfter (CMTime)

    The tolerance allowed after time.

Returns:

- (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.

Parameters:

  • time (CMTime)

    The time to which you would like to move the playback cursor.

  • toleranceBefore (CMTime)

    The tolerance allowed before time.

  • toleranceAfter (CMTime)

    The tolerance allowed after time.

  • completionHandler (Object)

    The block to invoke when the seek operation has either been completed or been interrupted.The block takes one argument:finishedIndicated whether the seek operation completed.

  • finished (BOOL finished)

    Indicated whether the seek operation completed.

Returns:

- (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.

Parameters:

  • rate (Float)

    The playback rate for the item.

  • itemTime (CMTime)

    The precise time at which to match playback of the item. To use the current item’s current time, specify kCMTimeInvalid.

  • hostClockTime (CMTime)

    The host time at which to synchronize playback. If you specify kCMTimeInvalid, the rate and time are set together without any external synchronization.

Returns: