createVideo
Create a Native Video View
When a game calls sud.createVideo to create a video component, the SDK passes the corresponding SUDOPVideo object to the App through createVideo:. The App must add the video's render view to an appropriate native container and implement layout, layering, controls, and full-screen behavior based on the object's state.
Method Declaration
- (void)createVideo:(SUDOPVideo *)video;Parameter
| Parameter | Type | Required | Description |
|---|---|---|---|
| video | SUDOPVideo * | Yes | The video object created by the SDK. It exposes the render view, layout parameters, playback state, and UI state callbacks. |
This callback does not use SUDOPStateHandle. Subsequent video operations and state changes are handled through SUDOPVideo.
Common SUDOPVideo Properties
Rendering and Layout
| Property | Type | Description |
|---|---|---|
| instanceID | NSInteger | Unique ID of the video instance. |
| renderView | UIView * | The video render view to add to the native view hierarchy. |
| renderLayer | CAEAGLLayer * | The render layer used by the SDK to connect the game media player. The App normally does not set it manually. |
| x / y | CGFloat | Coordinates of the video's top-left corner, in points. |
| width / height | CGFloat | Video component dimensions, in points. |
| frameInPoint | CGRect | Current requested layout frame, in points. Prefer this value when layout changes. |
| underGameView | BOOL | Whether the video should appear below the game view. |
Configuration and State
| Property | Type | Description |
|---|---|---|
| src | NSString * | Video resource URL. |
| poster | NSString * | Video poster URL. |
| objectFit | NSString * | Video scaling mode. |
| controls | BOOL | Whether playback controls should be displayed. |
| autoplay / loop / muted | BOOL | Whether the video autoplays, loops, or starts muted. |
| playing | BOOL | Whether the video is currently playing. |
| hasStartedPlayback | BOOL | Whether this instance has actually started playback. Use it to control poster visibility; autoplay alone does not immediately set it to YES. |
| disabled | BOOL | Whether the video is currently hidden. |
| fullScreen | BOOL | Whether the video is currently full screen. |
| currentTime / duration | NSTimeInterval | Current playback position and duration, in seconds. |
| bufferedTime | NSTimeInterval | The time up to which media has buffered, in seconds. |
For the complete creation options, see the game-side sud.createVideo documentation.
UI State Callbacks
When implementing a custom native video UI, set these callbacks as needed:
| Callback | When It Is Invoked |
|---|---|
| layoutChangedHandler | frameInPoint changes and the video layout must be updated. |
| layerChangedHandler | underGameView changes and the view hierarchy must be adjusted. |
| styleChangedHandler | The background color, scaling mode, or intrinsic video size changes. |
| progressChangedHandler | Playback progress changes and the progress UI must be refreshed. |
| bufferingProgressChangedHandler | Buffering progress changes; receives bufferedTime and duration in seconds. |
| endedHandler | Playback reaches its natural end. |
| waitingHandler | Playback enters a waiting or buffering state. |
| errorHandler | Playback fails; receives an error code and message. |
| visibilityChangedHandler | The video is enabled or disabled and its visibility must be updated. |
| requestFullScreenHandler | The game requests full screen. Call notifyFullScreenChanged:YES after completing the transition. |
| exitFullScreenHandler | The game requests an exit from full screen. Call notifyFullScreenChanged:NO after restoring the layout. |
| destroyHandler | The video instance is destroyed and the native video UI and callbacks must be removed. |
Native play, pause, stop, and seek controls should call play, pause, stop, and seek: respectively to synchronize the operation with the game.
Example
This example demonstrates only the minimum render-view integration. A production implementation should also handle controls, layering, full screen, and cleanup as required by the product.
@property (nonatomic, strong) UIView *videoContainerView;
@property (nonatomic, strong) SUDOPVideo *currentVideo;
- (void)createVideo:(SUDOPVideo *)video {
if (!video || !video.renderView) {
return;
}
self.currentVideo = video;
UIView *renderView = video.renderView;
[renderView removeFromSuperview];
renderView.frame = video.frameInPoint;
[self.videoContainerView addSubview:renderView];
__weak typeof(self) weakSelf = self;
video.layoutChangedHandler = ^(SUDOPVideo *changedVideo) {
weakSelf.currentVideo.renderView.frame = changedVideo.frameInPoint;
};
video.visibilityChangedHandler = ^(SUDOPVideo *changedVideo, BOOL visible) {
changedVideo.renderView.hidden = !visible;
};
video.destroyHandler = ^(SUDOPVideo *destroyedVideo) {
[destroyedVideo.renderView removeFromSuperview];
weakSelf.currentVideo = nil;
};
}Notes
- Add
renderViewto a container that uses the same coordinate system as the game view so thatframeInPointcan be applied directly. - Readjust the video's position relative to the game view whenever
underGameViewchanges. - Perform UIKit view updates on the main thread.
play,pause,stop,seek:, anddestroyexecute on the main thread. Calls from a background thread are dispatched to the main queue.destroyis idempotent and emits its notification only once. Layout, style, and playback commands are ignored after destruction.seek:preserves fractional-second precision. Non-finite values are ignored and negative values are clamped to 0.- Avoid strongly capturing the page or player in blocks. Clear callbacks and remove the UI when the video is destroyed.
- If your project integrates
SUDOPWrappedClientKit, you can use its default wrapped client and video player implementation. Implement the UI behavior above when using a custom delegate.
