Skip to content

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 ​

objectivec
- (void)createVideo:(SUDOPVideo *)video;

Parameter ​

ParameterTypeRequiredDescription
videoSUDOPVideo *YesThe 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 ​

PropertyTypeDescription
instanceIDNSIntegerUnique ID of the video instance.
renderViewUIView *The video render view to add to the native view hierarchy.
renderLayerCAEAGLLayer *The render layer used by the SDK to connect the game media player. The App normally does not set it manually.
x / yCGFloatCoordinates of the video's top-left corner, in points.
width / heightCGFloatVideo component dimensions, in points.
frameInPointCGRectCurrent requested layout frame, in points. Prefer this value when layout changes.
underGameViewBOOLWhether the video should appear below the game view.

Configuration and State ​

PropertyTypeDescription
srcNSString *Video resource URL.
posterNSString *Video poster URL.
objectFitNSString *Video scaling mode.
controlsBOOLWhether playback controls should be displayed.
autoplay / loop / mutedBOOLWhether the video autoplays, loops, or starts muted.
playingBOOLWhether the video is currently playing.
hasStartedPlaybackBOOLWhether this instance has actually started playback. Use it to control poster visibility; autoplay alone does not immediately set it to YES.
disabledBOOLWhether the video is currently hidden.
fullScreenBOOLWhether the video is currently full screen.
currentTime / durationNSTimeIntervalCurrent playback position and duration, in seconds.
bufferedTimeNSTimeIntervalThe 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:

CallbackWhen It Is Invoked
layoutChangedHandlerframeInPoint changes and the video layout must be updated.
layerChangedHandlerunderGameView changes and the view hierarchy must be adjusted.
styleChangedHandlerThe background color, scaling mode, or intrinsic video size changes.
progressChangedHandlerPlayback progress changes and the progress UI must be refreshed.
bufferingProgressChangedHandlerBuffering progress changes; receives bufferedTime and duration in seconds.
endedHandlerPlayback reaches its natural end.
waitingHandlerPlayback enters a waiting or buffering state.
errorHandlerPlayback fails; receives an error code and message.
visibilityChangedHandlerThe video is enabled or disabled and its visibility must be updated.
requestFullScreenHandlerThe game requests full screen. Call notifyFullScreenChanged:YES after completing the transition.
exitFullScreenHandlerThe game requests an exit from full screen. Call notifyFullScreenChanged:NO after restoring the layout.
destroyHandlerThe 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.

objectivec
@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 renderView to a container that uses the same coordinate system as the game view so that frameInPoint can be applied directly.
  • Readjust the video's position relative to the game view whenever underGameView changes.
  • Perform UIKit view updates on the main thread.
  • play, pause, stop, seek:, and destroy execute on the main thread. Calls from a background thread are dispatched to the main queue.
  • destroy is 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.