Peter 9bc996374f Add 'submodules/AsyncDisplayKit/' from commit '02bedc12816e251ad71777f9d2578329b6d2bef6'
git-subtree-dir: submodules/AsyncDisplayKit
git-subtree-mainline: d06f423e0ed3df1fed9bd10d79ee312a9179b632
git-subtree-split: 02bedc12816e251ad71777f9d2578329b6d2bef6
2019-06-11 18:42:43 +01:00

3.2 KiB
Executable File

title layout permalink prevPage nextPage
ASVideoNode docs /docs/video-node.html network-image-node.html map-node.html

ASVideoNode provides a convenient and performant way to display videos in your app.

Note: If you use `ASVideoNode` in your application, you must link `AVFoundation` since it uses `AVPlayerLayer` and other `AVFoundation` classes under the hood.

Basic Usage

The easiest way to use ASVideoNode is to assign it an AVAsset.

SwiftObjective-C
ASVideoNode *videoNode = [[ASVideoNode alloc] init];

AVAsset *asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://www.w3schools.com/html/mov_bbb.mp4"]]; videoNode.asset = asset;

let videoNode = ASVideoNode()

let asset = AVAsset(url: URL(string: "http://www.w3schools.com/html/mov_bbb.mp4")!)
videoNode.asset = asset

Autoplay, Autorepeat, and Muting

You can configure the way your video node reacts to various events with a few simple BOOLs.

If you'd like your video to automaticaly play when it enters the visible range, set the shouldAutoplay property to YES. Setting shouldAutoRepeat to YES will cause the video to loop indefinitely, and, of course, setting muted to YES will turn the video's sound off.

To set up a node that automatically plays once silently, you would just do the following.

SwiftObjective-C
videoNode.shouldAutoplay = YES;
videoNode.shouldAutorepeat = NO;
videoNode.muted = YES;
videoNode.shouldAutoplay = true
videoNode.shouldAutorepeat = false
videoNode.muted = true

Placeholder Image

Since video nodes inherit from ASNetworkImageNode, you can use the URL property to assign a placeholder image. If you decide not to, the first frame of your video will automatically decoded and used as the placeholder instead.

ASVideoNode Delegate

There are a ton of delegate methods available to you that allow you to react to what's happening with your video. For example, if you want to react to the player's state changing, you can use:

SwiftObjective-C
- (void)videoNode:(ASVideoNode *)videoNode willChangePlayerState:(ASVideoNodePlayerState)state toState:(ASVideoNodePlayerState)toState;
videoNode(_:willChange:to:)

The easiest way to see them all is to take a look at the ASVideoNode header file.