tencent cloud

Custom Player
Last updated: 2025-06-03 18:00:36
Custom Player
Last updated: 2025-06-03 18:00:36
If the superapp has integrated third-party players or developed its own, it can use the delegate API to replace the mini program's default player with its existing player.
To implement a custom player, the prerequisite is to customize the mini program SDK APIs by creating a class that conforms to the TMFMiniAppSDKDelegate protocol:
#import <TCMPPSDK/TCMPPSDK.h>

@interface MIniAppDemoSDKDelegateImpl : NSObject <TMFMiniAppSDKDelegate>

@end
You need to implement the corresponding delegate method to return the player instance that conforms to the protocol when creating the player instance:

- (id<TMAVideoPlayerDelegate>)app:(TMFMiniAppInfo *_Nonnull)app createVideoViewWithFrame:(CGRect)frame andVideoParams:(NSDictionary *)params;
The TMAVideoPlayerDelegate API provides various properties (such as playback URL, mute status, and whether to show the progress bar) and events (such as play, pause, playback speed, and entering/exiting full screen) that can be implemented in the corresponding methods. The complete API is as follows:

@property (nonatomic, strong) NSString *tmaVideoPlayerCurrentURL; // Playback URL

/*
tmaVideoPlayerHostVC is used to record the VC where the video player is located, usually a WebView, to perform related operations when entering or exiting full screen. You only need to add @synthesize tmaVideoPlayerHostVC; in your custom player.
No other operations are required.
*/
@property(nonatomic, weak) UIViewController<TMAVideoViewFullScreenProtocol> *tmaVideoPlayerHostVC;

// Cover image URL

@property(nonatomic, strong) NSString *tmaVideoPlayerPosterUrl;

// Specify the initial playback position

@property(nonatomic, assign) CGFloat tmaVideoPlayerInitialTime;

// Whether to show control buttons

@property(nonatomic, assign) BOOL tmaVideoPlayerShowControls;

// Whether to repeat playback

@property(nonatomic, assign) BOOL tmaVideoPlayerRepeat;

// Whether to mute

@property(nonatomic, assign) BOOL tmaVideoPlayerIsMuted;

// Whether to show the center play button

@property(nonatomic, assign) BOOL tmaVideoPlayerShowCenterPlayButton;

// Control videoGravity, contentsGravity, and poster's contentMode with three values: contain, fill, cover
@property(nonatomic, strong) NSString *tmaVideoPlayerObjectFitMode;

// Full screen orientation with three values: 0 UIInterfaceOrientationPortrait, 90 UIInterfaceOrientationLandscapeRight, -90 UIInterfaceOrientationLandscapeLeft
@property(nonatomic, strong) NSNumber *tmaVideoPlayerFullscreenDirection;

// Whether to support double-tap to pause/play

@property(nonatomic, assign) BOOL tmaVideoPlayerEnablePlayGesture;

// The title in the top left corner in full-screen mode

@property(nonatomic, strong) NSString *tmaVideoPlayerFullscreenTitle;

// Whether to show the progress bar

@property(nonatomic, assign) BOOL tmaVideoPlayerShowProgress;

// Whether to show the full screen button

@property(nonatomic, assign) BOOL tmaVideoPlayerShowFullscreenBtn;

// Whether to show the play button in the bottom control bar

@property(nonatomic, assign) BOOL tmaVideoPlayerShowPlayBtn;

// Whether to show the mute button

@property(nonatomic, assign) BOOL tmaVideoPlayerShowMuteButton;

// Whether to support progress adjustment gestures

@property(nonatomic, assign) BOOL tmaVideoPlayerEnableProgressGesture;

// Whether to enable volume and brightness adjustment gestures when not in full screen

@property(nonatomic, assign) BOOL tmaVideoPlayerPageGestureWhenNotFullscreen;
@property(nonatomic, strong) NSArray *tmaVideoPlayerDanmuList;

// Whether to autoplay

@property(nonatomic, assign) BOOL tmaVideoPlayerAutoPlay;

// Whether to allow background playback

@property(nonatomic, assign) BOOL tmaVideoPlayerBackgroundPlayback;

// Whether to enable picture-in-picture

@property(nonatomic, assign) BOOL tmaVideoPlayerIsPictureInPicture;

// Records whether it is in full-screen mode

@property(nonatomic, assign) BOOL tmaVideoPlayerIsFullScreen;

// Whether to automatically rotate when entering full screen

@property(nonatomic, assign) BOOL tmaVideoPlayerEnableAutoRotation;



/*
Used to send player events to the mini program
*/
@property(nonatomic, strong) void(^ _Nullable tmaVideoPlayerStatusBlock)(MAVideoPlayerStatus status, NSDictionary * _Nullable params);

// Play

- (void)tmaVideoPlayerPlay;

// Pause

- (void)tmaVideoPlayerPause;

// Stop

- (void)tmaVideoPlayerStop;

// Adjust the playback progress

- (void)tmaVideoPlayerSeekDuration:(CGFloat)duration;

// Playback rate

- (void)tmaVideoPlayerPlayBackRate:(CGFloat)rate;

// Enter full screen

- (void)tmaVideoPlayerEnterFullScreen;

// Exit full screen

- (void)tmaVideoPlayerExitFullScreen;

// Whether to show the system status bar in full screen

- (void)tmaVideoPlayerShowStatusBar:(BOOL)show;

// Insert on-screen comment

- (void)tmaVideoPlayerInsertDanmuText:(NSString *_Nonnull)content color:(NSString *_Nonnull)colorStr;

// Interrupt playback

- (void)tmaVideoPlayerInterruptPlay;

// Resume playback

- (void)tmaVideoPlayerResumePlay;

// Pause when the page disappears

- (void)tmaVideoPlayerPauseWhenDiappear;

// Play when the page resumes

- (void)tmaVideoPlayerPlayWhenAppear;

// Whether to support background playback

- (void)tmaVideoPlayerRequestBackgroundPlayback:(BOOL)state;


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback