Commit e520aa3c cgx

优化音频播放列表

1 个父辈 12dcca73
...@@ -125,6 +125,9 @@ ...@@ -125,6 +125,9 @@
} }
- (void)updateUI:(SubAudioModel *)model indexPath:(NSIndexPath *)indexPath { - (void)updateUI:(SubAudioModel *)model indexPath:(NSIndexPath *)indexPath {
self.numberLb.hidden = NO;
self.playVedioImgV.hidden = !self.numberLb.hidden;
self.numberLb.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1]; self.numberLb.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
self.timeLb.text = model.play_time; self.timeLb.text = model.play_time;
self.titleLb.text = model.audio_name; self.titleLb.text = model.audio_name;
...@@ -145,11 +148,11 @@ ...@@ -145,11 +148,11 @@
- (void)updatePlayingAudio { - (void)updatePlayingAudio {
self.numberLb.hidden = YES; self.numberLb.hidden = YES;
#warning 需要提供夜间模式图标 self.playVedioImgV.hidden = !self.numberLb.hidden;
self.playVedioImgV.image = [UIImage imageNamed:@"ic_list_playing_normal"];
self.tryLab.hidden = YES; self.tryLab.hidden = YES;
self.pleyerBtn.hidden = !self.tryLab.hidden; self.pleyerBtn.hidden = !self.tryLab.hidden;
[self.playVedioImgV dk_setImagePicker:DKImagePickerWithNames(@"ic_list_playing_normal", @"dk_ic_list_playing_normal", @"ic_list_playing_normal")];
[self.pleyerBtn setImage:[UIImage imageNamed:@"ic_list_suspend_normal"] forState:UIControlStateNormal]; [self.pleyerBtn setImage:[UIImage imageNamed:@"ic_list_suspend_normal"] forState:UIControlStateNormal];
} }
......
...@@ -11,7 +11,10 @@ ...@@ -11,7 +11,10 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@protocol CourseDetailControllerDelegate <NSObject> @protocol CourseDetailControllerDelegate <NSObject>
- (void)didSelectAudioWithIndex:(NSInteger)index; /// 用户点击音频
/// @param index 当前点击的音频下标
/// @param audios 已解锁的最新音频数据
- (void)didSelectAudioWithIndex:(NSInteger)index latestAudios:(NSArray *)audios;
@end @end
/// 课程详情页(音频列表) /// 课程详情页(音频列表)
...@@ -19,8 +22,15 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -19,8 +22,15 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) CourseModel *courseModel; @property (nonatomic, strong) CourseModel *courseModel;
@property (nonatomic, weak) id<CourseDetailControllerDelegate> delegate; @property (nonatomic, weak) id<CourseDetailControllerDelegate> delegate;
@property (nonatomic, assign) NSInteger playingIndex;
/*
用于标记从哪个页面进入到音频列表界面
YES:播放页面点击播放列表;
NO:课程页面点击UICollectionViewCell;
*/
@property (nonatomic, assign) BOOL isFromPlayer; @property (nonatomic, assign) BOOL isFromPlayer;
/// 正在播放的音频索引(-1:没有正在播放的音频,0,1,2...:有正在播放的音频)
@property (nonatomic, assign) NSInteger playingIndex;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -35,6 +35,17 @@ ...@@ -35,6 +35,17 @@
self.titleLab.text = self.courseModel.audio_name; self.titleLab.text = self.courseModel.audio_name;
[self getAudiosData]; [self getAudiosData];
if (self.isFromPlayer == NO) {
// 给音频列表页面添加通知(从播放页面跳转到音频列表),通知发送时机:音频列表(从播放页面跳转到音频列表)登录成功后
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOriAudioList) name:@"UnlockAudioSuccessNoti" object:nil];
}
}
- (void)dealloc {
if (self.isFromPlayer == NO) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UnlockAudioSuccessNoti" object:nil];
}
} }
- (void)getAudiosData { - (void)getAudiosData {
...@@ -61,21 +72,61 @@ ...@@ -61,21 +72,61 @@
return NO; return NO;
} }
#pragma mark - Actions
- (void)backAction { - (void)backAction {
[super backAction]; [super backAction];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
- (void)unlockAction { - (void)unlockAction {
// 开始第一节
if ([LoginUtils getUserLoginData]) { if ([LoginUtils getUserLoginData]) {
[self jumpToMusicPlayerControllerWithIndex:0];
} else { } else {
[LoginUtils jumpToLoginControllerWithTarget:self selector:@selector(updateAfterLoginSuccess)]; [LoginUtils jumpToLoginControllerWithTarget:self selector:@selector(updateAfterLoginSuccess)];
} }
} }
#pragma mark - 跳转到播放页面
- (void)jumpToMusicPlayerControllerWithIndex:(NSInteger)index {
// 筛选已经解锁的音频
NSMutableArray *tmpArr = [NSMutableArray array];
[self.subAudioArr enumerateObjectsUsingBlock:^(SubAudioModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.is_lock == 0) {
[tmpArr addObject:obj];
}
}];
// 播放页面点击播放列表进入
if (self.isFromPlayer) {
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectAudioWithIndex:latestAudios:)]) {
[self.delegate didSelectAudioWithIndex:index latestAudios:[tmpArr copy]];
}
[self.navigationController popViewControllerAnimated:YES];
return;
}
// 课程列表跳转过来的(跳转到播放页面)
MusicPlayerController *playerVC = [[MusicPlayerController alloc] init];
playerVC.currentIndex = index;
playerVC.playAudios = [tmpArr copy];
playerVC.courseModel = self.courseModel;
UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:playerVC];
[self presentViewController:naviVC animated:YES completion:nil];
}
#pragma mark - 登录成功后刷新
- (void)updateAfterLoginSuccess { - (void)updateAfterLoginSuccess {
[self.unlockBtn setTitle:@"开始第一节" forState:UIControlStateNormal]; [self.unlockBtn setTitle:@"开始第一节" forState:UIControlStateNormal];
[self getAudiosData]; [self getAudiosData];
if (self.isFromPlayer) { [[NSNotificationCenter defaultCenter] postNotificationName:@"UnlockAudioSuccessNoti" object:nil]; }
}
#pragma mark - 刷新最开始的音频列表
- (void)refreshOriAudioList {
[self.unlockBtn setTitle:@"开始第一节" forState:UIControlStateNormal];
[self getAudiosData];
} }
#pragma mark - UITableViewDelegate, UITableViewDataSource #pragma mark - UITableViewDelegate, UITableViewDataSource
...@@ -92,11 +143,9 @@ ...@@ -92,11 +143,9 @@
if (self.subAudioArr.count > indexPath.row) { if (self.subAudioArr.count > indexPath.row) {
SubAudioModel *model = self.subAudioArr[indexPath.row]; SubAudioModel *model = self.subAudioArr[indexPath.row];
[cell updateUI:model indexPath:indexPath]; [cell updateUI:model indexPath:indexPath];
// 标记已播放的音频 // 从播放页面点击播放列表进入,标记正在播放的音频
if (self.isFromPlayer) { if (self.isFromPlayer && self.playingIndex == indexPath.row) {
if (self.playingIndex == indexPath.row) { [cell updatePlayingAudio];
[cell updatePlayingAudio];
}
} }
} }
return cell; return cell;
...@@ -114,29 +163,7 @@ ...@@ -114,29 +163,7 @@
[LoginUtils jumpToLoginControllerWithTarget:self selector:@selector(updateAfterLoginSuccess)]; [LoginUtils jumpToLoginControllerWithTarget:self selector:@selector(updateAfterLoginSuccess)];
} }
} else { } else {
// 播放页面点击播放列表进入 [self jumpToMusicPlayerControllerWithIndex:indexPath.row];
if (self.isFromPlayer) {
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectAudioWithIndex:)]) {
[self.delegate didSelectAudioWithIndex:indexPath.row];
}
[self.navigationController popViewControllerAnimated:YES];
return;
}
// 课程列表跳转过来的(跳转到播放页面)
MusicPlayerController *playerVC = [[MusicPlayerController alloc] init];
playerVC.currentIndex = indexPath.row;
// 筛选已经解锁的音频
NSMutableArray *tmpArr = [NSMutableArray array];
[self.subAudioArr enumerateObjectsUsingBlock:^(SubAudioModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.is_lock == 0) {
[tmpArr addObject:obj];
}
}];
playerVC.playAudios = [tmpArr copy];
playerVC.courseModel = self.courseModel;
UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:playerVC];
[self presentViewController:naviVC animated:YES completion:nil];
} }
} }
} }
......
...@@ -137,6 +137,10 @@ ...@@ -137,6 +137,10 @@
} }
- (void)launchPlayer { - (void)launchPlayer {
// 不是正在播放的状态需要先停止
if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; }
if (self.currentIndex >= self.playAudios.count) { return; }
SubAudioModel *audioModel = self.playAudios[self.currentIndex]; SubAudioModel *audioModel = self.playAudios[self.currentIndex];
[self.playerView updatePlayerView:audioModel]; [self.playerView updatePlayerView:audioModel];
[self.audioStream playFromURL:[NSURL URLWithString:audioModel.audio_url]]; [self.audioStream playFromURL:[NSURL URLWithString:audioModel.audio_url]];
...@@ -211,15 +215,27 @@ ...@@ -211,15 +215,27 @@
- (void)jumpToPlaylistController { - (void)jumpToPlaylistController {
CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init]; CourseDetailController *coureDetailVC = [[CourseDetailController alloc] init];
coureDetailVC.courseModel = self.courseModel; coureDetailVC.courseModel = self.courseModel;
coureDetailVC.playingIndex = self.currentIndex; coureDetailVC.playingIndex = self.audioStream.isPlaying ? self.currentIndex : -1;
coureDetailVC.isFromPlayer = YES; coureDetailVC.isFromPlayer = YES;
coureDetailVC.delegate = self; coureDetailVC.delegate = self;
[self.navigationController pushViewController:coureDetailVC animated:YES]; [self.navigationController pushViewController:coureDetailVC animated:YES];
} }
#pragma mark - CourseDetailControllerDelegate #pragma mark - CourseDetailControllerDelegate
- (void)didSelectAudioWithIndex:(NSInteger)index { - (void)didSelectAudioWithIndex:(NSInteger)index latestAudios:(NSArray *)audios {
if (self.currentIndex == index) { return; } // 更新音频数据
self.playAudios = audios;
// 点击当前传过来音频
if (self.currentIndex == index) {
if (self.streamState == kFsAudioStreamStopped) {
[self.audioStream play];
} else if (self.streamState == kFsAudioStreamPaused) {
// 恢复播放
[self.audioStream pause];
}
return;
}
self.currentIndex = index; self.currentIndex = index;
[self launchPlayer]; [self launchPlayer];
} }
......
...@@ -406,8 +406,6 @@ ...@@ -406,8 +406,6 @@
if (!_timer) { if (!_timer) {
WS(weakSelf); WS(weakSelf);
_timer = [NSTimer timerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) { _timer = [NSTimer timerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
DSLog(@"============");
// 暂停播放 // 暂停播放
if (weakSelf.countTime == 0) { if (weakSelf.countTime == 0) {
[weakSelf.timer setFireDate:[NSDate distantFuture]]; [weakSelf.timer setFireDate:[NSDate distantFuture]];
......
{
"images" : [
{
"filename" : "dk_ic_list_playing_normal.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "dk_ic_list_playing_normal@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "dk_ic_list_playing_normal@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!