VideoPlayerViewController
@interface VideoPlayerViewController : UIViewController
The VideoPlayerViewController is a UIViewController sub-class that embeds an AVPlayer object within a provided UIView. It primes the AVPlayer with a video asset to play. It also allows the offset of the audio and video tracks to be adjusted with regards to the asset’s timeline.
This class also contains the heuristics to allow the video player to catch-up to a specified position using a strategy that minimises user experience disruption (e.g. by speeding up the play speed or doing a seek).
-
The native video player this class uses to play videos.
Declaration
Objective-C
@property (readonly, atomic) VideoPlayerView *videoPlayer;
Swift
var videoPlayer: VideoPlayerView! { get }
-
An offset in seconds by which the audio tyrack can be moved forward or back. This is used typically to callibrate the playback so that currentTime reports the time when the sound actually reaches the speakers.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSTimeInterval audioOffset;
Swift
var audioOffset: TimeInterval { get set }
-
An offset in seconds by which the audio tyrack can be moved forward or back. This is used typically to callibrate the playback so that currentTime reports the time when the sound actually reaches the speakers.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSTimeInterval videoOffset;
Swift
var videoOffset: TimeInterval { get set }
-
A BOOL indicating whether the player should loop the file
Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL shouldLoop;
Swift
var shouldLoop: Bool { get set }
-
An AudioPlayerState value representing the current internal playback and file state of the AudioPlayer instance.
Declaration
Objective-C
@property (readonly, nonatomic) VideoPlayerState state;
Swift
var state: VideoPlayerState { get }
-
File or HTTP URL for companion video content e.g. H264/MP4 video file or HLS VOD stream
Declaration
Objective-C
@property (readwrite, strong, nonatomic) NSURL *videoURL;
Swift
var videoURL: URL! { get set }
-
The VideoPlayerDelegate that will handle the audio player callbacks
Declaration
Objective-C
@property (readwrite, strong, nonatomic) id<VideoPlayerDelegate> delegate;
Swift
var delegate: VideoPlayerDelegate! { get set }
-
Provides the current offset in the video file as an NSTimeInterval (i.e. in seconds). When setting this it will determine the correct frame offset and perform a seek to the new time offset. - warning: Make sure the new current time offset is less than the
duration
or you will receive an invalid seek assertion. There are methods to cause the player to adapt its playback to move to a new position e.g. seekToTime and setRate.Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSTimeInterval currentTime;
Swift
var currentTime: TimeInterval { get set }
-
Provides the duration of the video asset loaded for playback. Note: this will only be populated after the AVPlayer pipelines have been primed and the first video packets decoded.
Declaration
Objective-C
@property (readonly, nonatomic) NSTimeInterval duration;
Swift
var duration: TimeInterval { get }
-
Property specifying whether the video player is playing or not.
Declaration
Objective-C
@property (readonly, atomic) BOOL isPlaying;
Swift
var isPlaying: Bool { get }
-
Property specifying whether the video player is playing or not.
Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSString *fillMode;
Swift
var fillMode: String! { get set }
-
rate of playback
Declaration
Objective-C
@property (readonly, nonatomic) float rate;
Swift
var rate: Float { get }
-
time ranges currently in buffer
Declaration
Objective-C
@property (readonly, nonatomic) NSArray<NSValue *> *loadedTimeRanges;
Swift
var loadedTimeRanges: [NSValue]! { get }
-
Initialise video player controller with a UIView in which to embed video player
Declaration
Objective-C
- (id)initWithParentView:(UIView *)parentView;
Swift
init!(parentView: Any!)
Parameters
parentView
a UIView instance within which to embed video player
Return Value
a VideoPlayerController instance
-
Initialise video player controller with a UIView in which to embed video player and register a delegate to receive callbacks.
Declaration
Objective-C
- (id)initWithParentView:(UIView *)parentView Delegate:(id<VideoPlayerDelegate>)playerDelegate;
Swift
init!(parentView: Any!, delegate playerDelegate: VideoPlayerDelegate!)
Parameters
parentView
UIView instance within which to embed video player
playerDelegate
a delegate object implementing the VideoPlayerDelegate
Return Value
a VideoPlayerController instance
-
Stops the VideoPlayerViewController and remove player view from parent view
Declaration
Objective-C
- (void)stopAndRemoveFromParentView;
Swift
func stopAndRemoveFromParentView()
-
Pauses player
Declaration
Objective-C
- (void)pause;
Swift
func pause()
-
Start the video playback. If the video player was paused, it resumes from last paused position
Declaration
Objective-C
- (void)play;
Swift
func play()
-
Synchronizes the playback rate and time of the current item with an external source. Essentially, the AVPlayer will resynchronise its media item to fulfill a new relationship between the media timeline and the host clock timeline as specified by a [itemTime, hostClockTime] pair. The rate specifies the speed at which the media time progresses w.r.t the host clock time.
Declaration
Objective-C
- (void)setRate:(float)rate time:(Float64)itemTime atHostTime:(Float64)hostClockTime;
Swift
func setRate(_ rate: Float, time itemTime: Float64, atHostTime hostClockTime: Float64)
Parameters
rate
play speed
itemTime
time position on media timeline in seconds
hostClockTime
time position in seconds on host clock. If the SystemClock mirrors the host clock, then it can be used as a time source for host clock time.
-
Seek to time position in the media.
Declaration
Objective-C
- (void)seekToTime:(Float64)time;
Swift
func seek(toTime time: Float64)
Parameters
time
time position on media timeline.
-
Subscribe an observer to receive playback time notifications (VideoPlayerCurrentTimeNotification) every ‘periodMS’ milliseconds
Declaration
Objective-C
- (BOOL)addPeriodicTime:(uint32_t)periodMs Observer:(id)observer;
Swift
func addPeriodicTime(_ periodMs: UInt32, observer: Any!) -> Bool
Parameters
periodMs
time interval in milliseconds, lowest value allowed is 100 ms.
observer
an observer object wishing to receive periodic notifications (of type ) from this video player
-
Unsubscribe an observing object from this player’s notifications.
Declaration
Objective-C
- (void)removePeriodicTimeObserver:(id)observer;
Swift
func removePeriodicTimeObserver(_ observer: Any!)
Parameters
observerObj
an observer object which has subscribed to receive periodic notifications (of type ) from this video player