git clone git@github.com:tencentyun/SuperPlayer_iOS.git
Cloning to 'SuperPlayer_iOS'...remote: Enumerating objects: 2637, done.remote: Counting objects: 100% (644/644), done.remote: Compressing objects: 100% (333/333), done.remote: Total 2637 (delta 227), reused 524 (delta 170), pack-reused 1993Receiving the object: 100% (2637/2637), 571.20 MiB | 3.94 MiB/s, done.Processing delta: 100% (1019/1019), done.
Filename | Description |
SDK | The folder of the Player component’s frameworks and static libraries. |
Demo | The folder of the Player demo. |
App | The entry point UI. |
SuperPlayerDemo | The Player demo. |
SuperPlayerKit | The Player component. |
SuperPlayer
as a Pod:pod 'SuperPlayer
podfile
:pod 'SuperPlayer/Player'
podfile
:pod 'SuperPlayer/Player_Premium'
podfile
:pod 'SuperPlayer/Professional'
pod install
or pod update
.TXLiteAVSDK_Player_Premium.framework
into your project and select Do Not Embed.Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer
to your project directory.AFNetworking
, SDWebImage
, Masonry
, and TXLiteAVSDK_Player
.TXLiteAVSDK_Player
manually, you need to add the required system frameworks and libraries:TXFFmpeg.xcframework
and TXSoundTouch.scframework
under the TXLiteAVSDK_Player
file as dynamic libraries.
TXLiteAVSDK_Player
as a pod, no libraries need to be added.SuperPlayerView
object to play videos (SuperPlayerView
is the main class of the player).// Import the header file#import <SuperPlayer/SuperPlayer.h>// Create a player_playerView = [[SuperPlayerView alloc] init];// Set a delegate for events_playerView.delegate = self;// Set the parent view. _playerView will be automatically added under holderView._playerView.fatherView = self.holderView;
FileId
in VOD or URL. We recommend you integrate the FileId
because it allows you to use more VOD capabilities.psign
to specify the video to play; otherwise, the playback may fail. For more information on how to transcode a video and generate psign
, see Play back a video with the Player component and Player Signature.// If you haven't enabled hotlink protection and a "no v4 play info" error occurs, transcode your video using the Adaptive-HLS template (ID: 10) or get the playback URL of the video and play it by URL.SuperPlayerModel *model = [[SuperPlayerModel alloc] init];model.appId = 1400329071;// Configure AppIdmodel.videoId = [[SuperPlayerVideoId alloc] init];model.videoId.fileId = @"5285890799710173650"; // Configure `FileId`// `psign` is a player signature. For more information on the signature and how to generate it, see [Player Signature](https://www.tencentcloud.com/document/product/266/38099).model.videoId.pSign = @"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTQwMDMyOTA3MSwiZmlsZUlkIjoiNTI4NTg5MDc5OTcxMDE3MzY1MCIsImN1cnJlbnRUaW1lU3RhbXAiOjEsImV4cGlyZVRpbWVTdGFtcCI6MjE0NzQ4MzY0NywidXJsQWNjZXNzSW5mbyI6eyJ0IjoiN2ZmZmZmZmYifSwiZHJtTGljZW5zZUluZm8iOnsiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3fX0.yJxpnQ2Evp5KZQFfuBBK05BoPpQAzYAWo6liXws-LzU";[_playerView playWithModelNeedLicence:model];
SuperPlayerModel *model = [[SuperPlayerModel alloc] init];model.videoURL = @"http://your_video_url.mp4"; // Enter the URL of the video to play[_playerView playWithModelNeedLicence:model];
SuperPlayerModel *model = [[SuperPlayerModel alloc]init];//Add your video file to the project, and then get the file path of the video through NSBundleNSString *filePath = [[NSBundle mainBundle] pathForResource:@"your_video_name" ofType:@"mp4"];model.videoURL = [filePath stringByReplacingOccurrencesOfString:@"file://" withString:@""];[_playerView playWithModelNeedLicence:model];
resetPlayer
to reset the player and free up memory.[_playerView resetPlayer];
- (void)superPlayerFullScreenChanged:(SuperPlayerView *)player {// You can customize the logic after switching to the full screen mode here}
// The back button tapping event- (void)superPlayerBackAction:(SuperPlayerView *)player;Triggered by tapping of the back button at the top left// The exit full screen notification- (void)superPlayerFullScreenChanged:(SuperPlayerView *)player;
// Use the API below to enable/disable screen locking@property(nonatomic, assign) BOOL isLockScreen;
SPDefaultControlView
object and, during initialization of the player view, set an event for the on-screen comment button of SPDefaultControlView
. The on-screen comment content and view are customized by yourself. For details, see CFDanmakuView
, CFDanmakuInfo
, and CFDanmaku
in SuperPlayerDemo
.SPDefaultControlView *dv = (SPDefaultControlView *)**self**.playerView.controlView;[dv.danmakuBtn addTarget:**self** action:**@selector**(danmakuShow:) forControlEvents:UIControlEventTouchUpInside];
// The following attributes are required--------// On-screen time@property(nonatomic, assign) CGFloat duration;// On-screen time in the center, at top, and at bottom@property(nonatomic, assign) CGFloat centerDuration;// On-screen comment line height@property(nonatomic, assign) CGFloat lineHeight;// Spacing between on-screen comment lines@property(nonatomic, assign) CGFloat lineMargin;// Maximum number of on-screen comment lines@property(nonatomic, assign) NSInteger maxShowLineCount;// Maximum number of on-screen comment lines in the center, at top, and at bottom@property(nonatomic, assign) NSInteger maxCenterLineCount;
// Tapping the back button during playback in portrait mode will trigger the API[SuperPlayerWindowShared setSuperPlayer:self.playerView];[SuperPlayerWindowShared show];// The API triggered by tapping the floating window to return to the main windowSuperPlayerWindowShared.backController = self;
PLAY_ACTION_AUTO_PLAY
, the thumbnail will be displayed before the first video frame is loaded.PLAY_ACTION_MANUAL_PLAY
, videos are played only after users tap the play button, and the thumbnail will be displayed until the first video frame is loaded.SuperPlayerModel *model = [[SuperPlayerModel alloc] init];SuperPlayerVideoId *videoId = [SuperPlayerVideoId new];videoId.fileId = @"8602268011437356984";model.appId = 1400329071;model.videoId = videoId;// Playback mode, which can be set to automatic (`PLAY_ACTION_AUTO_PLAY`) or manual (`PLAY_ACTION_MANUAL_PLAY`)model.action = PLAY_ACTION_MANUAL_PLAY;// Specify the URL of an online file to use as the thumbnail. If `coverPictureUrl` is not set, the thumbnail configured in the VOD console will be used.model.customCoverImageUrl = @"http://1500005830.vod2.myqcloud.com/6c9a5118vodcq1500005830/cc1e28208602268011087336518/MXUW1a5I9TsA.png";[self.playerView playWithModelNeedLicence:model];
// Step 1. Create a `NSMutableArray` for the loop dataNSMutableArray *modelArray = [NSMutableArray array];SuperPlayerModel *model = [SuperPlayerModel new];SuperPlayerVideoId *videoId = [SuperPlayerVideoId new];videoId.fileId = @"8602268011437356984";model.appId = 1252463788;model.videoId = videoId;[modelArray addObject:model];model = [SuperPlayerModel new];videoId = [SuperPlayerVideoId new];videoId.fileId = @"4564972819219071679";model.appId = 1252463788;model.videoId = videoId;[modelArray addObject:model];// Step 2. Call the loop API of `SuperPlayerView`[self.playerView playWithModelListNeedLicence:modelArray isLoopPlayList:YES startIndex:0];
(void)playWithModelListNeedLicence:(NSArray *)playModelList isLoopPlayList:(BOOL)isLoop startIndex:(NSInteger)index;
Parameter | Type | Description |
playModelList | NSArray * | Loop data list |
isLoop | Boolean | Whether to loop the playlist |
index | NSInteger | Index of the video from which to start the playback |
// Enter the PiP modeif (![TXVodPlayer isSupportPictureInPicture]) {return;}[_vodPlayer enterPictureInPicture];// Exit the PiP mode[_vodPlayer exitPictureInPicture];
// Step 1. Create a preview modelTXVipWatchModel *model = [[TXVipWatchModel alloc] init];model.tipTtitle = @"You can preview 15 seconds of the video. Become a subscriber to watch the full video.";model.canWatchTime = 15;// Step 2. Set the preview modelself.playerView.vipWatchModel = model;// Step 3. Call the method below to display the preview[self.playerView showVipTipView];
TXVipWatchModel
class parameter description:Parameter | Type | Description |
tipTtitle | NSString | Pop-up message |
canWatchTime | float | Preview duration in seconds |
// Step 1. Create a video source information modelSuperPlayerModel * playermodel = [SuperPlayerModel new];// Add other information of the video source// Step 2. Create a dynamic watermark modelDynamicWaterModel *model = [[DynamicWaterModel alloc] init];// Step 3. Set the data of the dynamic watermarkmodel.dynamicWatermarkTip = @"shipinyun";model.textFont = 30;model.textColor = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:0.8];playermodel.dynamicWaterModel = model;// Step 4. Call the method below to display the dynamic watermark[self.playerView playWithModelNeedLicence:playermodel];
DynamicWaterModel
:Parameter | Type | Description |
dynamicWatermarkTip | NSString | Watermark text |
textFont | CGFloat | Font size |
textColor | UIColor | Text color |
VideoCacheView
(cache selection list view) is used to select and download videos at different definitions. After selecting the definition in the top-left corner, click the option of the video to be downloaded. When a check mark appears, the download has started. After clicking the video download list button below, you will be redirected to the Activity where VideoDownloadListView
is located.// Step 1. Initialize the cache selection list view//@property (nonatomic, strong) VideoCacheView *cacheView;_cacheView = [[VideoCacheView alloc] initWithFrame:CGRectZero];_cacheView.hidden = YES;[self.playerView addSubview:_cacheView];// Step 2. Set the options of the video being played back[_cacheView setVideoModels:_currentPlayVideoArray currentPlayingModel:player.playerModel];// Click event of the **video download list** button- (UIButton *)viewCacheListBtn;
- (void)setVideoModels:(NSArray *)models currentPlayingModel:(SuperPlayerModel *)currentModel;
Parameter | Type | Description |
models | NSArray | The video data model of the download list |
SuperPlayerModel | currentModel | The video data model of the video being played back |
VideoCacheListView
(video download list) // Add data, which is obtained from the `TXVodDownloadManager#getDownloadMediaInfoList` API.NSArray<TXVodDownloadMediaInfo *> *array = [[[TXVodDownloadManager shareInstance] getDownloadMediaInfoList] mutableCopy];for (TXVodDownloadMediaInfo *info in array) {VideoCacheListModel *model = [[VideoCacheListModel alloc] init];model.mediaInfo = info;[self.videoCacheArray addObject:model];}// List items support operations such as click to play and hold and press to delete.- (void)longPress:(UILongPressGestureRecognizer *)longPress; // Hold and press
NSArray<TXVodDownloadMediaInfo *> *mediaInfoList = [[TXVodDownloadManager shareInstance] getDownloadMediaInfoList];TXVodDownloadMediaInfo *mediaInfo = [mediaInfoList firstObject];SuperPlayerUrl *superPlayerUrl = [[SuperPlayerUrl alloc] init];superPlayerUrl.title = @"*********";superPlayerUrl.url = mediaInfo.playpath;NSArray<SuperPlayerUrl *> *multiVideoURLs = @[superPlayerUrl];SuperPlayerModel *playerModel = [[SuperPlayerModel alloc] init];playerModel.multiVideoURLs = multiVideoURLs;[self.playerView playWithModelNeedLicence:playerModel];
// Step 1. Get the image sprite and timestamp information in the `onPlayEvent` callback (this works only if the video is played back through `playWithModelNeedLicence`)[self.playerView playWithModelNeedLicence:playerModel];// Step 2. Get keyframes and image sprite information in the `VOD_PLAY_EVT_GET_PLAYINFO_SUCC` callback event for `playWithModelNeedLicence`NSString *imageSpriteVtt = [param objectForKey:VOD_PLAY_EVENT_IMAGESPRIT_WEBVTTURL]?:@"";NSArray<NSString *> *imageSpriteList = [param objectForKey:VOD_PLAY_EVENT_IMAGESPRIT_IMAGEURL_LIST];NSArray<NSURL *> *imageURLs = [self convertImageSpriteList:imageSpriteList];[self.imageSprite setVTTUrl:[NSURL URLWithString:imageSpriteVtt] imageUrls:imageURLs];// Step 3. Display the obtained timestamp information and image sprite on the UIif (self.isFullScreen) {thumbnail = [self.imageSprite getThumbnail:draggedTime];}if (thumbnail) {[self.fastView showThumbnail:thumbnail withText:timeStr];}
SuperPlayerModel#subtitlesArray
.// // Pass in subtitle url, subtitle name, and subtitle typeSuperPlayerSubtitles *subtitleModel = [[SuperPlayerSubtitles alloc] init];subtitleModel.subtitlesUrl = @"https://mediacloud-76607.gzc.vod.tencent-cloud.com/DemoResource/TED-CN.srt";subtitleModel.subtitlesName = @"ex-cn-srt";subtitleModel.subtitlesType = 0;[subtitlesArray addObject:subtitleModel];// Play[self.playerView playWithModelNeedLicence:model];
// After the video starts playing, select the added external subtitles.- (void)controlViewSwitch:(UIView *)controlView withSubtitlesInfo:(TXTrackInfo *)info preSubtitlesInfo:(TXTrackInfo *)preInfo {if (info.trackIndex == -1) {[self.vodPlayer deselectTrack:preInfo.trackIndex];self->_lastSubtitleIndex = -1;} else {if (preInfo.trackIndex != -1) {// Deselect other subtitles if they are not needed[self.vodPlayer deselectTrack:preInfo.trackIndex];}// Select subtitles. [self.vodPlayer[self.vodPlayer selectTrack:info.trackIndex];self->_lastSubtitleIndex = info.trackIndex;}}
TXPlayerSubtitleRenderModel *model = [[TXPlayerSubtitleRenderModel alloc] init];model.canvasWidth = 1920; // Subtitle render canvas widthmodel.canvasHeight = 1080; // Subtitle render canvas heightmodel.isBondFontStyle = NO; // Set whether the subtitle font is boldmodel.fontColor = 0xFF000000; // Set the subtitle font color, default white and opaque[_txVodPlayer setSubtitleStyle:model];
// Step 1: Configure the FileId that supports ghost watermark to play the video.SuperPlayerModel *model = [[SuperPlayerModel alloc] init];model.appId = 1500006438;model.videoId = [[SuperPlayerVideoId alloc] init];model.videoId.fileId = @"387702307847129127";model.videoId.pSign =@"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDAwNjQzOCwiZmlsZUlkIjoiMzg3NzAyMzA3ODQ3MTI5MTI3IiwiY29udGVudEluZm8iOnsiYXVkaW9WaWRlb1R5cGUiOiJSYXdBZGFwdGl2ZSIsInJhd0FkYXB0aXZlRGVmaW5pdGlvbiI6MTB9LCJjdXJyZW50VGltZVN0YW1wIjoxNjg2ODgzMzYwLCJnaG9zdFdhdGVybWFya0luZm8iOnsidGV4dCI6Imdob3N0IGlzIHdhdGNoaW5nIn19.0G2o4P5xVZ7zFlFUgBLntfX03iGxK9ntD_AONClUUno";[_playerView playWithModelNeedLicence:model];// Step 2: After SuperPlayerView receives the PLAY_EVT_GET_PLAYINFO_SUCC event, obtain the content of the ghost watermark for display.- (void)onPlayEvent:(TXVodPlayer *)player event:(int)EvtID withParam:(NSDictionary *)param {dispatch_async(dispatch_get_main_queue(), ^{if (EvtID == PLAY_EVT_PLAY_EVT_GET_PLAYINFO_SUCCPLAY_PROGRESS) {NSString *ghostWaterText = [param objectForKey:@"EVT_KEY_WATER_MARK_TEXT"];if (ghostWaterText && ghostWaterText.length > 0) {DynamicWaterModel *model = [[DynamicWaterModel alloc] init];model.showType = ghost;model.duration = self.playerModel.duration;model.dynamicWatermarkTip = ghostWaterText;model.textFont = 30;model.textColor = [UIColor redColor];if (![self.subviews containsObject:self.watermarkView]) {[self addSubview:self.watermarkView];[self.watermarkView mas_makeConstraints:^(MASConstraintMaker *make) {make.edges.equalTo(self);}];}[self.watermarkView setDynamicWaterModel:model];}}};}
Demo
directory, run the pod update
command to generate the TXLiteAVDemo.xcworkspace
file again.
この記事はお役に立ちましたか?