Not optimized for short videos | Optimized short video |
| |
pod 'TUIPlayerShortVideo' ,:path => '../../../SDK/TUIPlayerShortVideoSDK/'pod 'TUIPlayerCore' ,:path => '../../../SDK/TUIPlayerCoreSDK/'
- [AppDelegate application:didFinishLaunchingWithOptions:]
make the following configuration:NSString * const licenceURL = @"<Obtained licenseUrl>";NSString * const licenceKey = @"<The key obtained>";[TXLiveBase setLicenceURL:licenceUrl key:licenceKey];[[TXLiveBase sharedInstance] setDelegate:self];
- (TUIShortVideoView *)videoView {if (!_videoView) {///Setting up a custom UITUIPlayerShortVideoUIManager *uiManager = [[TUIPlayerShortVideoUIManager alloc] init];[uiManager setControlViewClass: TUIPlayerShortVideoControlView.class];[uiManager setControlViewClass: TUIPSControlLiveView.class viewType:TUI_ITEM_VIEW_TYPE_LIVE];[uiManager setControlViewClass: TUIPSControlCustomView.class viewType:TUI_ITEM_VIEW_TYPE_CUSTOM];[uiManager setLoadingView:[[TUIPSDLoadingView alloc] init]];_videoView = [[TUIShortVideoView alloc] initWithUIManager:uiManager];_videoView.delegate = self;_videoView.customCallbackDelegate = self;//_videoView.isAutoPlay = NO;// Set your playback strategyTUIPlayerVodStrategyModel *model = [[TUIPlayerVodStrategyModel alloc] init];model.mPreloadConcurrentCount = 1;model.preDownloadSize = 1;model.enableAutoBitrate = NO;// live strategyTUIPlayerLiveStrateyModel *liveStrateyModel = [[TUIPlayerLiveStrateyModel alloc] init];[_videoView setShortVideoLiveStrategyModel:liveStrateyModel];}return _videoView;}
videoView.frame = self.view.bounds;[self.view addSubview:self.videoView];
TUIPlayerVideoModel *model1 = [[TUIPlayerVideoModel alloc] init]; ///Video DataTUIPlayerLiveModel *model2 = [[TUIPlayerLiveModel alloc] init]; ///Live dataTUIPlayerDataModel *model3 = [[TUIPlayerDataModel alloc] init]; ///Custom Data/// Here, you can decide the amount of data per page based on your business situation.NSArray *videos1 = @[model1,model2,model3];[self.videoView setShortVideoModels:videos1];
TUIPlayerVideoModel *model1 = [[TUIPlayerVideoModel alloc] init]; ///Video DataTUIPlayerLiveModel *model2 = [[TUIPlayerLiveModel alloc] init]; ///Live dataTUIPlayerDataModel *model3 = [[TUIPlayerDataModel alloc] init]; ///Custom Data/// Here, you can decide the amount of data per page based on your business situation.NSArray *videos2 = @[model1,model2,model3];-(void)onReachLast {///Here you can make a data index record and continue to insert your 3rd 4th 5th 6th...group of data[self.videoView appendShortVideoModels:videos2];}
Parameter name | Implication |
isAutoPlay | Whether to automatically play the first video when loading for the first time, default is YES |
videos | Read-only property, get the data currently in the video list |
currentVideoModel | The video model currently playing |
currentVideoIndex | Index of the video currently playing |
currentPlayerStatus | The current player's playback status |
isPlaying | Is the current player playing |
delegate | delegate |
refreshControl | Set the pull-down refresh control |
initWithUIManager | Initialization |
setShortVideoStrategyModel | Set the live broadcast strategy |
setShortVideoLiveStrategyModel | Set the live broadcast strategy |
setShortVideoModels | Setting up a data source for the first time |
appendShortVideoModels | Add video data source |
removeAllVideoModels | Delete all video data |
setPlaymode | Video playback mode, single loop or list loop, the former is the default |
pause | Pause |
resume | Resume |
destoryPlayer | Destroy the player |
didScrollToCellWithIndex | Jump to the video with the specified index |
startLoading | Display loading image |
stopLoading | Hide loading icon |
currentPlayerSupportedBitrates | The bitrate supported by the currently playing video |
bitrateIndex | Get the bitrate index of the current playback |
switchResolution:index: | Switch resolution |
pausePreload | Pause preloading |
resumePreload | Resume preload |
getDataManager | Get Data Manager |
getVodStrategyManager | Get the On-Demand Policy Manager |
getLiveStrategyManager | Get the Live Strategy Manager |
Parameter name | Implication |
enableLog | Whether to allow printing logs, the default is NO |
TUIPlayerConfig *config = [TUIPlayerConfig new];config.enableLog = YES;[[TUIPlayerCore shareInstance] setPlayerConfig:config];
Parameter name | Implication |
mPreloadConcurrentCount | The number of video caches, default is 3 |
mPreloadBufferSizeInMB | Pre-play size, in MB, default 0.5MB |
preferredResolution | Preferred resolution, default 720 * 1280 |
progressInterval | The progress bar callback interval, in milliseconds, default is 500ms |
renderMode | Canvas fill style, the default image adapts to the screen to keep the picture intact |
extInfoMap | Additional parameters, reserved |
enableAutoBitrate | Whether to enable adaptive bitrate, default is NO |
mediaType | Set the media type |
maxBufferSize | Maximum preload size, in MB, default 10MB, this setting will affect playableDuration, the larger the setting, the more pre-cached |
mResumeModel | Resume mode, default value is TUI_RESUM_MODEL_NONE |
preDownloadSize | Pre-download size, in MB, default 1MB |
enableAccurateSeek | Whether to seek accurately, the default is YES. After turning on accurate seek, the seek time will be 200ms longer on average |
audioNormalization
| Volume balance. Loudness range: -70~0 (LUFS). This configuration requires LiteAVSDK 11.7 and above. The following constants are for reference: Off: AUDIO_NORMALIZATION_OFF (TXVodPlayConfig.h) On (standard loudness): AUDIO_NORMALIZATION_STANDARD (TXVodPlayConfig.h) On (low loudness): AUDIO_NORMALIZATION_LOW (TXVodPlayConfig.h) On (high loudness): AUDIO_NORMALIZATION_HIGH (TXVodPlayConfig.h) The default value is AUDIO_NORMALIZATION_OFF. |
isLastPrePlay | Whether to keep the last pre-play, the default is NO |
subtitleRenderModel | Subtitle style |
TUIPlayerStrategyModel *model = [[TUIPlayerStrategyModel alloc] init];model.mPreloadConcurrentCount = 1;model.preDownloadSize = 1;model.enableAutoBitrate = NO;model.mRenderMode = TUI_RENDER_MODE_FILL_SCREEN;model.mResumeModel = TUI_RESUM_MODEL_LAST;[_videoView setShortVideoStrategyModel:model];
Parameter name | Implication |
isLastPrePlay | Whether to keep the last pre-play, the default is NO |
mRenderMode | Canvas fill style, default V2TXLiveFillModeFill |
enablePictureInPicture | YES: Enable the PIP function; NO: Disable the PIP function. Default value: NO. |
volume | The volume of the player, ranging from 0 to 100. Default value: 100. |
maxAutoAdjustCacheTime | The maximum time for automatic adjustment of the player cache, in seconds. The value must be greater than 0. The default value is 5. |
minAutoAdjustCacheTime | The minimum time for automatic adjustment of the player cache, in seconds. The value must be greater than 0. The default value is 1. |
isShowDebugView | Whether to display the debug overlay of player status information. Default value: NO. |
TUIPlayerLiveStrategyModel *liveStrategyModel = [[TUIPlayerLiveStrategyModel alloc] init];[_videoView setShortVideoLiveStrategyModel:liveStrategyModel];
TUIPlayerVodStrategyManager *VodStrategyManager = [_videoView getVodStrategyManager]TUIPlayerVodStrategyManager *LiveStrategyManager = [_videoView getLiveStrategyManager]
[VodStrategyManager setRenderMode:TUI_RENDER_MODE_FILL_EDGE];[LiveStrategyManager setRenderMode:V2TXLiveFillModeFill];
Parameter name | Implication |
TUIPlayerDataModel | Basic data types |
TUIPlayerVideoModel | Video data type, inherited from TUIPlayerDataModel |
TUIPlayerLiveModel | Vive data type, inherited from TUIPlayerDataModel |
Parameter name | Implication |
modelType | Model Type |
extInfo | Business data |
onExtInfoChangedBlock | ExtInfo The block where the data has changed |
extInfoChangeNotify | Notify extInfo that data has changed |
asVodModel | Force conversion to TUIPlayerVideoModel type |
asLiveModel | Force conversion to TUIPlayerLiveModel type |
Parameter name | Implication |
videoUrl | Video URL |
coverPictureUrl | Cover picture url |
duration | duration |
appId | appid |
fileId | fileId |
pSign | Signature String |
subtitles | Subtitle information |
config | Separate configuration of video, see TUIPlayerVideoConfig for details |
Parameter name | Implication |
liveUrl | Live URL |
coverPictureUrl | cover picture url |
TUIPlayerVideoModel *model = [[TUIPlayerVideoModel alloc] init];model.videoUrl = @"xxxx";model.coverPictureUrl = @"xxxx";model.duration = @"xxxx";model.appId = @"xxxx";model.fileId = @"xxxx";model.pSign = @"xxxx";NSDictionary *extr = @{@"name":@"@Mars",@"titile":@"This is a vod broadcast interface",@"des":@"This is a vod broadcast interface"};model.extInfo = extr;[modelArray addObject:model];
TUIPlayerLiveModel *model = [[TUIPlayerLiveModel alloc] init];model.liveUrl = @"xxxx";model.coverPictureUrl = @"xxxx";NSDictionary *extr = @{@"name":@"@Mars",@"liveTitile":@"This is a live broadcast interface",@"liveDes":@"This is a live broadcast interface"};model.extInfo = extr;
/// 1 CarouselTUIPlayerDataModel *model = [[TUIPlayerDataModel alloc] init];NSDictionary *extr = @{@"images":@"xxxx",@"url":@"https://cloud.tencent.com",@"titile":@"This is a picture carousel display interface",@"des":@"This is a picture carousel display interface",@"name":@"@Mars",@"type":@"imageCycle"};model.extInfo = extr;[modelArray insertObject:model atIndex:1];/// 2 Graphic AdsTUIPlayerDataModel *model1 = [[TUIPlayerDataModel alloc] init];NSDictionary *extr1 = @{@"adUrl":@"https://cloud.tencent.com",@"adUrl":@"https://cloud.tencent.com/document/product",@"adTitile":@"This is a web display interface",@"adDes":@"This is a web display interface",@"name":@"@Mars",@"type":@"ad"};model1.extInfo = extr1;[modelArray insertObject:model1 atIndex:1];
///1、Delete the data and view at index 1
[[self.videoView getDataManager] removeData:1];///2、Add a set of data to index 9TUIPlayerVideoModel *model = [[TUIPlayerVideoModel alloc] init];model.viewType = TUI_ITEM_VIEW_TYPE_CUSTOM;[[self.videoView getDataManager] addData:model index:9];
Parameter name | Implication |
removeData | Remove data by index |
removeRangeData | Remove data by range |
removeDataByIndex | Remove data by index array |
addData:index | Add data by index |
addRangeData:startIndex | Add data from a certain index according to the model array |
replaceData:index | Replace data by index |
replaceRangeData:startIndex | Replace data from a certain index in the model array |
getDataByPageIndex | Read data at a certain index |
getCurrentDataCount | Get the total number of data in the current playlist |
getCurrentIndex | Get the data index of the current playback interface |
getCurrentModel | Get the data model of the current playback interface |
TUIPlayerShortVideoUIManager *uiManager = [[TUIPlayerShortVideoUIManager alloc] init];[uiManager setControlViewClass: TUIPSControlView.class];[uiManager setLoadingView:[[TUIPSLoadingView alloc] init]];[uiManager setBackgroundView:[UIView new]];_videoView = [[TUIShortVideoView alloc] initWithUIManager:uiManager];
Parameter name | Implication |
setLoadingView | Setting up the loading graph |
setBackgroundView | Set the background image |
setErrorView | Setting the error interface |
setControlViewClass | Set the video control layer * @param ViewClass control layer class, ViewClass is the video control View you have encapsulated, including controls such as progress bar, time label, etc. * It will be covered on the video window as a whole, and its size is consistent with the video window |
setControlViewClass
:viewType | Set up different types of video control layers |
getLoadingView | Get the loading image View instance |
getBackgroundView | Get the background image View instance |
getErrorView | Get the error interface View instance |
getControlViewClass | Get the video control interface View class |
getControlViewClassWithViewType | Get different types of video control interface classes |
Parameter name | Implication |
delegate | A reverse proxy for interaction between the control layer and the playback layer |
model | The currently playing video model |
currentPlayerStatus | The current player's playback status |
showCenterView | Display center view |
hideCenterView | Hide center view |
showLoadingView | Display loading graph |
hiddenLoadingView | Hide loading image |
setDurationTime | Total video time |
setCurrentTime | Current playback time |
setProgress | Progress bar progress |
showSlider | Show progress bar |
hideSlider | Hide progress bar |
reloadControlData | Triggering a view refresh |
getPlayer | Get the player object |
onPlayEvent | Get player events |
getVideoLayerRect | Get the changes of the video rendering area |
getVideoWidget | Get the video rendering layer object |
Parameter name | Implication |
delegate | A reverse proxy for interaction between the control layer and the playback layer |
model | Current playback data model |
reloadControlData | Triggering a view refresh |
getPlayer | Get the player object |
getVideoLayerRect | Get the video layer area |
getVideoWidget | Get the video rendering layer |
Parameter name | Implication |
delegate | A reverse proxy for interaction between the control layer and the playback layer |
model | Current playback data model |
reloadControlData | Triggering a view refresh |
Type | video | live | Custom (slideshow) | Custom (graphic and text ads) |
example | | | | |
@interface TUIPSControlView : UIView<TUIPlayerShortVideoControl>@property (nonatomic, strong) TUIPlayerVideoModel *videoModel@end@implementation TUIPSControlView-(instancetype)initWithFrame:(CGRect)frame {if ([super initWithFrame:frame]){/// UI layout code}return self;}-(void)setModel:(TUIPlayerVideoModel *)model {_model = model;/// data}@end
@interface TUIPSControlLiveView : UIView<TUIPlayerShortVideoLiveControl>@property (nonatomic, strong) TUIPlayerLiveModel *videoModel@end@implementation TUIPSControlLiveView-(instancetype)initWithFrame:(CGRect)frame {if ([super initWithFrame:frame]){/// UI layout code}return self;}-(void)setModel:(TUIPlayerLiveModel *)model {_model = model;/// data}@end
@interface TUIPSControlCustomView : UIView<TUIPlayerShortVideoCustomControl>@property (nonatomic, strong) TUIPlayerDataModel *videoModel@end@implementation TUIPSControlCustomView-(instancetype)initWithFrame:(CGRect)frame {if ([super initWithFrame:frame]){/// UI layout code}return self;}-(void)setModel:(TUIPlayerDataModel *)model {_model = model;/// dataNSDictionary *dic = model.extInfo;NSString *adTitile = [dic objectForKey:@"adTitile"];NSString *adDes = [dic objectForKey:@"adDes"];NSString *adUrl = [dic objectForKey:@"adUrl"];NSString *name = [dic objectForKey:@"name"];NSString *type = [dic objectForKey:@"type"];if ([type isEqualToString:@"ad"]) { ///Graphic Adsself.webView.hidden = NO;self.cycleScrollView.hidden = YES;self.desLabel.textColor = [UIColor blackColor];self.nameLabel.textColor = [UIColor blackColor];[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:adUrl]]];} else if ([type isEqualToString:@"imageCycle"]) { ///Carouselself.webView.hidden = YES;self.cycleScrollView.hidden = NO;self.desLabel.textColor = [UIColor whiteColor];self.nameLabel.textColor = [UIColor whiteColor];NSString *imagesStr = [dic objectForKey:@"images"];NSArray *imagesArray = [imagesStr componentsSeparatedByString:@"<:>"];self.cycleScrollView.imageURLStringsGroup = imagesArray;}}@end
TUIPlayerShortVideoUIManager *uiManager = [[TUIPlayerShortVideoUIManager alloc] init];[uiManager setControlViewClass: TUIPSControlView.class viewType:TUI_ITEM_VIEW_TYPE_VOD];[uiManager setControlViewClass: TUIPSControlLiveView.class viewType:TUI_ITEM_VIEW_TYPE_LIVE];[uiManager setControlViewClass: TUIPSControlCustomView.class viewType:TUI_ITEM_VIEW_TYPE_CUSTOM];
_videoView = [[TUIShortVideoView alloc] initWithUIManager:uiManager];
// Set your playback strategyTUIPlayerVodStrategyModel *model = [[TUIPlayerVodStrategyModel alloc] init];model.mPreloadConcurrentCount = 1;model.preDownloadSize = 1;model.enableAutoBitrate = NO;[_videoView setShortVideoStrategyModel:model];// live strategyTUIPlayerLiveStrateyModel *liveStrateyModel = [[TUIPlayerLiveStrateyModel alloc] init];[_videoView setShortVideoLiveStrategyModel:liveStrateyModel];
Type | Data model | UI Templates |
Vod | TUIPlayerVideoModel | TUIPSControlView |
Live | TUIPlayerLiveModel | TUIPSControlLiveView |
Custom types (carousel, graphic ads, etc.) | TUIPlayerDataModel | TUIPSControlCustomView |
-(void)setModel:(TUIPlayerVideoModel *)model {if ([_model observationInfo]) {[_model removeObserver:self forKeyPath:@"preloadState"];}_model = model;[model addObserver:self forKeyPath:@"preloadState" options:NSKeyValueObservingOptionNew context:nil];NSDictionary *dic = model.extInfo;NSString *iconUrl = [dic objectForKey:@"iconUrl"];NSString *advertise = [dic objectForKey:@"advertise"];NSString *name = [dic objectForKey:@"name"];NSString *title = [dic objectForKey:@"title"];NSString *topic = [dic objectForKey:@"topic"];self.iconImageView.image = [UIImage imageNamed:iconUrl];[self.adButton setTitle:advertise forState:UIControlStateNormal];self.nameLabel.text= name;self.themeLabel.text = topic;self.desLabel.text = title;[self updatePreloadState];[self updateLickCount];model.onExtInfoChangedBlock = ^(id _Nonnull extInfo) {[self updateLickCount];};}
-(void)setModel:(TUIPlayerLiveModel *)model {_model = model;NSDictionary *dic = model.extInfo;NSString *adTitile = [dic objectForKey:@"liveTitile"];NSString *adDes = [dic objectForKey:@"liveDes"];NSString *name = [dic objectForKey:@"name"];self.nameLabel.text = name;self.desLabel.text = adTitile;}
-(void)setModel:(TUIPlayerDataModel *)model {_model = model;NSDictionary *dic = model.extInfo;NSString *adTitile = [dic objectForKey:@"adTitile"];NSString *adDes = [dic objectForKey:@"adDes"];NSString *adUrl = [dic objectForKey:@"adUrl"];NSString *name = [dic objectForKey:@"name"];NSString *type = [dic objectForKey:@"type"];self.desLabel.text = adTitile;self.nameLabel.text = name;if ([type isEqualToString:@"web"]) {self.webView.hidden = NO;self.cycleScrollView.hidden = YES;self.desLabel.textColor = [UIColor blackColor];self.nameLabel.textColor = [UIColor blackColor];[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:adUrl]]];} else if ([type isEqualToString:@"imageCycle"]) {self.webView.hidden = YES;self.cycleScrollView.hidden = NO;self.desLabel.textColor = [UIColor whiteColor];self.nameLabel.textColor = [UIColor whiteColor];NSString *imagesStr = [dic objectForKey:@"images"];NSArray *imagesArray = [imagesStr componentsSeparatedByString:@"<:>"];self.cycleScrollView.imageURLStringsGroup = imagesArray;}}
@protocol TUIPlayerShortVideoControlDelegate <NSObject>/*** Pause*/- (void)pause;/*** Resume*/- (void)resume;/*** Sliding scroll bar processing* @param time Slide distance*/- (void)seekToTime:(float)time;/*** Is it playing*/- (BOOL)isPlaying;/*** Reset video playback container* Used for scenarios where the video playback container needs to be reset after being removed*/- (void)resetVideoWeigetContainer;@optional/*** Custom callback events*/- (void)customCallbackEvent:(id)info;@end/////transferif (self.delegate && [self.delegate respondsToSelector:@selector(pause)]) {[self.delegate pause];}
@protocol TUIPlayerShortVideoLiveControlDelegate <NSObject>/*** pause*/- (void)pause;/*** resume*/- (void)resume;/*** Reset video playback container* Used for scenarios where the video playback container needs to be reset after being removed*/- (void)resetVideoWeigetContainer;@optional/*** Custom callback events*/- (void)customCallbackEvent:(id)info;@end/////transferif (self.delegate && [self.delegate respondsToSelector:@selector(pause)]) {[self.delegate pause];}
@protocol TUIPlayerShortVideoCustomControlDelegate <NSObject>@optional/*** Custom callback events*/- (void)customCallbackEvent:(id)info;@end/////transferif (self.delegate && [self.delegate respondsToSelector:@selector(customCallbackEvent:)]) {[self.delegate customCallbackEvent:@"test"];}
/// Get Data ManagerTUIShortVideoDataManager *dataManager = [self.videoView getDataManager];///Get the data modelTUIPlayerDataModel *model = [dataManager getDataByPageIndex:1];///Modify the data modelmodel.extInfo = @{@"key":@"value"}///Notify data model changes[model extInfoChangeNotify];
model.onExtInfoChangedBlock = ^(id _Nonnull extInfo) {[self updateLickCount];};
/// Volume balance. Loudness range: -70~0(LUFS). This configuration requires LiteAVSDK 11.7 and above./// The following constants are for reference/// Off: AUDIO_NORMALIZATION_OFF (TXVodPlayConfig.h)/// On (standard loudness): AUDIO_NORMALIZATION_STANDARD (TXVodPlayConfig.h)/// On (low loudness): AUDIO_NORMALIZATION_LOW (TXVodPlayConfig.h)/// On (high loudness): AUDIO_NORMALIZATION_HIGH (TXVodPlayConfig.h)/// The default value is AUDIO_NORMALIZATION_OFF.TUIPlayerVodStrategyModel *model = [[TUIPlayerVodStrategyModel alloc] init];model.audioNormalization = AUDIO_NORMALIZATION_STANDARD;[_videoView setShortVideoStrategyModel:model];
Was this page helpful?