Skip to content

Commit

Permalink
优化用户体验
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiruiou committed Mar 11, 2022
1 parent 272df60 commit c32dd57
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,39 @@ - (instancetype)init {
}
}

- (void)addObservers {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(updateLockScreenInfo)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}

// 更新锁屏界面信息
- (void)updateLockScreenInfo {
// 1.获取锁屏中心
MPNowPlayingInfoCenter *playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
// 初始化一个存放音乐信息的字典
NSMutableDictionary *playingInfoDict = [NSMutableDictionary dictionary];

// 2、设置名称
[playingInfoDict setObject:[NSString stringWithFormat:@"歌曲1"]
forKey:MPMediaItemPropertyTitle];
[playingInfoDict setObject:[NSString stringWithFormat:@"专辑1"]
forKey:MPMediaItemPropertyAlbumTitle];


// 3、设置封面的图片
UIImage *image = [UIImage imageNamed:@"TengXunYun_logo"];
if (image) {
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:image];
[playingInfoDict setObject:artwork forKey:MPMediaItemPropertyArtwork];
}

//音乐信息赋值给获取锁屏中心的nowPlayingInfo属性
playingInfoCenter.nowPlayingInfo = playingInfoDict;
}

- (void)dealloc {
NSLog(@"%@", LocalizeReplaceXX(LivePlayerLocalize(@"SuperPlayerDemo.MoviePlayer.xxtherelease"), NSStringFromClass(self.class)));
[_manager invalidateSessionCancelingTasks:YES resetSession:NO];
Expand All @@ -118,6 +151,8 @@ - (void)didMoveToParentViewController:(nullable UIViewController *)parent {
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"背景"];
Expand Down Expand Up @@ -182,6 +217,8 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];

[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
}

- (void)viewDidAppear:(BOOL)animated {
Expand All @@ -208,6 +245,8 @@ - (void)viewDidLoad {
_authParamArray = [NSMutableArray new];
_vodDataSourceArray = [NSMutableArray new];
_liveDataSourceArray = [NSMutableArray new];

[self addObservers];

if (self.videoURL) {
SuperPlayerModel *playerModel = [[SuperPlayerModel alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ +(NSDictionary *) getStreamInfo:(NSString*) audioVideoType media:(NSDictionary*)
return streamInfo;;
}

+(NSMutableArray *) parseResolutionName:(NSArray*) subStreamDictArray{
+(NSMutableArray *) parseResolutionName:(NSArray*)subStreamDictArray{
NSMutableArray *subStreamInfoArray = [NSMutableArray arrayWithCapacity:subStreamDictArray.count];
for (NSDictionary *resInfo in subStreamDictArray) {
SuperPlayerUrl *url = [[SuperPlayerUrl alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ - (NSString *)playingDefinitionUrl {
// 初始播放清晰度url获取失败,获取第一条转码流
if (url == nil) {
if (self.multiVideoURLs.count > 0) {
url = self.multiVideoURLs.firstObject.url;
url = self.multiVideoURLs.lastObject.url;
if (url) {
self.playingDefinition = self.multiVideoURLs.lastObject.title;
}
}
}
// 转码流获取失败,用原始地址
Expand Down
123 changes: 74 additions & 49 deletions Demo/TXLiteAVDemo/SuperPlayerKit/SuperPlayer/SuperPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ - (void)layoutSubviews {
[super layoutSubviews];
if (self.subviews.count > 0) {
UIView *innerView = self.subviews[0];
if ([innerView isKindOfClass:NSClassFromString(@"TXIJKSDLGLView")] || [innerView isKindOfClass:NSClassFromString(@"TXCAVPlayerView")]) {
if ([innerView isKindOfClass:NSClassFromString(@"TXIJKSDLGLView")] || [innerView isKindOfClass:NSClassFromString(@"TXCAVPlayerView")] || [innerView isKindOfClass:NSClassFromString(@"TXCThumbPlayerView")]) {
innerView.frame = self.bounds;
}
}
Expand Down Expand Up @@ -348,9 +348,6 @@ - (void)resume {
if (self.state == StatePrepare) {
self.state = StatePlaying;
[self.vodPlayer resume];
if (self.delegate && [self.delegate respondsToSelector:@selector(superPlayerDidStart:)]) {
[self.delegate superPlayerDidStart:self];
}
} else {
_isPrepare = YES;
}
Expand Down Expand Up @@ -558,45 +555,18 @@ - (void)configTXPlayer {
self.livePlayer = [[TXLivePlayer alloc] init];
self.livePlayer.delegate = self;
}
TXLivePlayConfig *config = [[TXLivePlayConfig alloc] init];
config.bAutoAdjustCacheTime = NO;
config.maxAutoAdjustCacheTime = 5.0f;
config.minAutoAdjustCacheTime = 5.0f;
config.headers = self.playerConfig.headers;
[self.livePlayer setConfig:config];

self.livePlayer.enableHWAcceleration = self.playerConfig.hwAcceleration;
[self setLivePlayerConfig];

[self.livePlayer startPlay:videoURL type:liveType];
[self.livePlayer setupVideoWidget:CGRectZero containView:self insertIndex:0];
TXCUrl *curl = [[TXCUrl alloc] initWithString:videoURL];
[self.livePlayer prepareLiveSeek:self.playerConfig.playShiftDomain bizId:curl.bizid];
[self.livePlayer setMute:self.playerConfig.mute];
[self.livePlayer setRenderMode:self.playerConfig.renderMode];
self.isPauseByUser = NO;
} else {
if (!self.vodPlayer) {
self.vodPlayer = [[TXVodPlayer alloc] init];
self.vodPlayer.vodDelegate = self;
}

TXVodPlayConfig *config = [[TXVodPlayConfig alloc] init];
config.smoothSwitchBitrate = YES;
if (self.playerConfig.maxCacheItem) {
// https://github.com/tencentyun/SuperPlayer_iOS/issues/64
config.cacheFolderPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/TXCache"];
config.maxCacheItems = (int)self.playerConfig.maxCacheItem;
}
config.progressInterval = 0.02;
self.vodPlayer.token = self.playerModel.drmToken;
config.headers = self.playerConfig.headers;

config.overlayIv = self.playerModel.overlayIv;
config.overlayKey = self.playerModel.overlayKey;
[self.vodPlayer setConfig:config];

self.vodPlayer.enableHWAcceleration = self.playerConfig.hwAcceleration;
[self.vodPlayer setStartTime:self.startTime];
self.startTime = 0;
[self setVodPlayConfig];

NSString *appParameter = [NSString stringWithFormat:@"spappid=%ld", self.playerModel.appId];
NSString *fileidParameter = [NSString stringWithFormat:@"spfileid=%@", self.playerModel.videoId.fileId];
Expand All @@ -606,14 +576,67 @@ - (void)configTXPlayer {
vodParamVideoUrl = [NSString appendParameter:drmtypeParameter WithOriginUrl:vodParamVideoUrl];

[self preparePlayWithVideoUrl:([self isSupportAppendParam] ? vodParamVideoUrl : videoURL)];
[self.vodPlayer setBitrateIndex:self.playerModel.playingDefinitionIndex];
}
[self resetControlViewWithLive:self.isLive shiftPlayback:self.isShiftPlayback isPlaying:self.state == StatePlaying ? YES : NO];
self.controlView.playerConfig = self.playerConfig;
self.repeatBtn.hidden = YES;
self.playDidEnd = NO;
[self.middleBlackBtn fadeOut:0.1];
}

[self.vodPlayer setRate:self.playerConfig.playRate];
[self.vodPlayer setMirror:self.playerConfig.mirror];
[self.vodPlayer setMute:self.playerConfig.mute];
[self.vodPlayer setRenderMode:self.playerConfig.renderMode];
[self.vodPlayer setLoop:self.loop];
- (void)setVodPlayConfig {
TXVodPlayConfig *config = [[TXVodPlayConfig alloc] init];
config.smoothSwitchBitrate = YES;
if (self.playerConfig.maxCacheItem) {
// https://github.com/tencentyun/SuperPlayer_iOS/issues/64
config.cacheFolderPath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingString:@"/TXCache"];
config.maxCacheItems = (int)self.playerConfig.maxCacheItem;
}
config.progressInterval = 0.02;
config.headers = self.playerConfig.headers;

config.overlayIv = self.playerModel.overlayIv;
config.overlayKey = self.playerModel.overlayKey;
[self.vodPlayer setConfig:config];

self.vodPlayer.token = self.playerModel.drmToken;

self.vodPlayer.enableHWAcceleration = self.playerConfig.hwAcceleration;
[self.vodPlayer setStartTime:self.startTime];
self.startTime = 0;

[self.vodPlayer setBitrateIndex:self.playerModel.playingDefinitionIndex];
[self.vodPlayer setRate:self.playerConfig.playRate];
[self.vodPlayer setMirror:self.playerConfig.mirror];
[self.vodPlayer setMute:self.playerConfig.mute];
[self.vodPlayer setRenderMode:self.playerConfig.renderMode];
[self.vodPlayer setLoop:self.loop];

[self.netWatcher startWatch];
__weak SuperPlayerView *weakSelf = self;
[self.netWatcher setNotifyTipsBlock:^(NSString *msg) {
SuperPlayerView *strongSelf = weakSelf;
if (strongSelf) {
[strongSelf showMiddleBtnMsg:msg withAction:ActionSwitch];
[strongSelf.middleBlackBtn fadeOut:2];
}
}];
}

- (void)setLivePlayerConfig {
TXLivePlayConfig *config = [[TXLivePlayConfig alloc] init];
config.bAutoAdjustCacheTime = NO;
config.maxAutoAdjustCacheTime = 5.0f;
config.minAutoAdjustCacheTime = 5.0f;
config.headers = self.playerConfig.headers;
[self.livePlayer setConfig:config];

self.livePlayer.enableHWAcceleration = self.playerConfig.hwAcceleration;
[self.livePlayer setupVideoWidget:CGRectZero containView:self insertIndex:0];
[self.livePlayer setMute:self.playerConfig.mute];
[self.livePlayer setRenderMode:self.playerConfig.renderMode];
self.isPauseByUser = NO;

[self.netWatcher startWatch];
__weak SuperPlayerView *weakSelf = self;
[self.netWatcher setNotifyTipsBlock:^(NSString *msg) {
Expand All @@ -623,11 +646,6 @@ - (void)configTXPlayer {
[strongSelf.middleBlackBtn fadeOut:2];
}
}];
[self resetControlViewWithLive:self.isLive shiftPlayback:self.isShiftPlayback isPlaying:self.state == StatePlaying ? YES : NO];
self.controlView.playerConfig = self.playerConfig;
self.repeatBtn.hidden = YES;
self.playDidEnd = NO;
[self.middleBlackBtn fadeOut:0.1];
}

- (void)preparePlayWithVideoUrl:(NSString *)videoUrl {
Expand Down Expand Up @@ -691,7 +709,6 @@ - (void)restart {
if ([self.vodPlayer supportedBitrates].count > 1) {
[self.vodPlayer resume];
} else {
[self.vodPlayer stopPlay];
[self.vodPlayer startPlay:url];
if (_playerModel.action == PLAY_ACTION_PRELOAD) {
[self resume];
Expand Down Expand Up @@ -762,9 +779,6 @@ - (void)detailPrepareState {
self.isPauseByUser = NO;
[self.controlView setPlayState:YES];
self.centerPlayBtn.hidden = YES;
if ([self.delegate respondsToSelector:@selector(superPlayerDidStart:)]) {
[self.delegate superPlayerDidStart:self];
}
}
}

Expand Down Expand Up @@ -823,6 +837,10 @@ - (void)prepareAutoplay {
self.autoPlay = YES; // 下次用户设置自动播放失效
[self pause];
}

if ([self.delegate respondsToSelector:@selector(superPlayerDidStart:)]) {
[self.delegate superPlayerDidStart:self];
}
}

#pragma mark - KVO
Expand Down Expand Up @@ -1018,6 +1036,8 @@ - (void)doubleTapAction:(UIGestureRecognizer *)gesture {
[self.controlView fadeShow];

if (self.playDidEnd) {
[self.vodPlayer stopPlay];
[self setVodPlayConfig];
[self restart];
} else {
if (self.isPauseByUser) {
Expand Down Expand Up @@ -1552,6 +1572,8 @@ + (UISlider *)volumeViewSlider {

- (void)controlViewPlay:(SuperPlayerControlView *)controlView {
if (self.playDidEnd) {
[self.vodPlayer stopPlay];
[self setVodPlayConfig];
[self restart];
} else {
[self controllViewPlayClick];
Expand Down Expand Up @@ -1844,6 +1866,7 @@ - (void)_removeOldPlayer {
if ([w isKindOfClass:NSClassFromString(@"TXCRenderView")]) [w removeFromSuperview];
if ([w isKindOfClass:NSClassFromString(@"TXIJKSDLGLView")]) [w removeFromSuperview];
if ([w isKindOfClass:NSClassFromString(@"TXCAVPlayerView")]) [w removeFromSuperview];
if ([w isKindOfClass:NSClassFromString(@"TXCThumbPlayerView")]) [w removeFromSuperview];
}
}

Expand Down Expand Up @@ -2141,6 +2164,8 @@ - (UIButton *)repeatBackBtn {
}

- (void)repeatBtnClick:(UIButton *)sender {
[self.vodPlayer stopPlay];
[self setVodPlayConfig];
[self restart];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ - (TXVodPlayer *)player {
_player.vodDelegate = self;
TXVodPlayConfig *config = [TXVodPlayConfig new];
config.maxBufferSize = 1;
config.smoothSwitchBitrate = YES;
config.smoothSwitchBitrate = NO;
_player.config = config;
[_player setRenderMode:RENDER_MODE_FILL_SCREEN];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ @implementation TXVideoUtils

// 此方法是为了构造请求视频数据的URL
+ (NSArray *)loadDefaultVideoUrls {
NSArray *locatVideoFileidArray = @[@"3701925920152292697", @"3701925920152048882", @"3701925920152283492", @"3701925920152283699", @"3701925920152049422", @"3701925920152049645", @"3701925920152293774", @"3701925920152293840", @"3701925920152050112", @"3701925920152294230", @"3701925920152285056", @"3701925920152285302", @"3701925920152050929", @"3701925920152131172", @"3701925920152286184", @"3701925920152286399"];
NSArray *locatVideoFileidArray = @[@"387702294394366256", @"387702294394228858", @"387702294394228636", @"387702294394228527", @"387702294167066523", @"387702294167066515", @"387702294168748446", @"387702294394227941"];
NSString *baseUrlStr = @"https://playvideo.qcloud.com/getplayinfo/v4";
NSMutableArray *videoUrlArray = [NSMutableArray array];
for (int i = 0; i < locatVideoFileidArray.count; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ - (void)setModel:(TXVideoModel *)model {

_model = model;

if ([model.width floatValue] > [model.height floatValue]) {
self.coverImgView.contentMode = UIViewContentModeScaleAspectFit;
}else {
self.coverImgView.contentMode = UIViewContentModeScaleAspectFill;
}
// if ([model.width floatValue] > [model.height floatValue]) {
// self.coverImgView.contentMode = UIViewContentModeScaleAspectFit;
// }else {
// self.coverImgView.contentMode = UIViewContentModeScaleAspectFill;
// }

self.coverImgView.contentMode = UIViewContentModeScaleAspectFit;

if (model.coverUrl) {
[self.coverImgView sd_setImageWithURL:[NSURL URLWithString:model.coverUrl] placeholderImage:[UIImage imageNamed:@"img_video_loading"]];
Expand Down

0 comments on commit c32dd57

Please sign in to comment.