歌词加载学习笔记
来源:互联网 发布:人工智能 百度网盘 编辑:程序博客网 时间:2024/04/29 17:17
1、首先从本地解析歌词文件。Lrc歌词文件时间来确定定时播放的数据。
通过
NSString *LRCPath = [[NSBundle mainBundle] pathForResource:[musicArray[musicArrayNumber] name] ofType:@"lrc"];
NSString *contentStr = [NSString stringWithContentsOfFile:LRCPath encoding:NSUTF8StringEncoding error:nil];
NSArray *array = [contentStr componentsSeparatedByString:@"\n"];
来解析数据,首先把所有的歌词文件加载到一个string中,然后通过通过相关的解码,来获得真实的数据,
array使用"/n"换行。从而得到一行数据,将所有的数据加载到一个数组中。
通过for循环遍历所有的数据,从而获得每一个数据来做相关的处理,根据歌词中的"]"字符串来分割相关的数据。
从而将时间和数据分开。然后再将时间根据":"和"."来分割开来,载入先关的数据。time和lrcstr。。。
- (NSString *)substringWithRange:(NSRange)aRange
可以从不规则的字符串中取出自己需要的字符,并且可以通过组装来实现例如时间的解集
通过这个格式来截取不规则格式的音频的时间。
通过定时器来定时加载歌词,其中通过歌词的长度来判读需要执行的歌词跳转,
//动态显示歌词-(void)displayLrc:(NSUInteger )timer{ for (int i =0 ; i<[timeArray count]; i++) { NSArray * array = [timeArray[i] componentsSeparatedByString:@":"]; NSUInteger currentTime = [array[0] intValue]*60 +[array[1] intValue]; if(i == ([timeArray count]-1)) { NSArray *array1 = [timeArray[timeArray.count-1] componentsSeparatedByString:@":"]; NSUInteger currentTime1 = [array1[0] intValue]*60 +[array1[1] intValue]; if (timer>currentTime1) { [self updataLRC:i]; } break;#warning 这里有一个问题 }else { //求出第一句的时间点,在第一句显示前的时间内一直加载第一句 NSArray *array2 = [timeArray[0] componentsSeparatedByString:@":"]; NSUInteger currentTime2 = [array2[0] intValue] * 60 + [array2[1] intValue]; if (timer < currentTime2) { [self updataLRC:0]; // NSLog(@"马上到第一句"); break; } NSArray *array3 = [timeArray[i+1] componentsSeparatedByString:@":"]; NSUInteger currentTime3 = [array3[0] intValue]*60 +[array3[1] intValue]; if (timer >=currentTime && timer<=currentTime3) { [self updataLRC:i]; break; } } }}
//更新选中的代码。-(void)updataLRC:(NSUInteger)lineNumber{ lrcLineNum = lineNumber; [centerTableView reloadData]; NSIndexPath *indexPath= [NSIndexPath indexPathForRow:lineNumber inSection:0 ]; NSLog(@"indexPath %@",indexPath); [centerTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; }
在tableview的datasorce方法中加载判断需要跳转的界面
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (tags == 0) { return [timeArray count]; } else if (tags ==1) { return [timeArray count]; } return [timeArray count];}
tags是绑定的全部变量,来判断点击事件触发的时候加载的是哪一个segment。
从而来返回相关的tableview cell的个数。
在tableview的datasorce方法 来实现动态加载歌词。
1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 2 { 3 static NSString* cellIndentify = @"LRCCell"; 4 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentify]; 5 if (cell ==nil) { 6 cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentify]; 7 } 8 if (indexPath.row == lrcLineNum) { 9 // cell.textLabel.text = lrcDict[timeArray[indexPath]];10 cell.textLabel.text = lrcDict[timeArray[indexPath.row]];11 cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];12 cell.textLabel.font = [UIFont systemFontOfSize:15];13 }else14 {15 cell.textLabel.text = lrcDict[timeArray[indexPath.row]];16 cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];17 cell.textLabel.font = [UIFont systemFontOfSize:13];18 }19 cell.backgroundColor = [UIColor clearColor];20 return cell;21 }
第一次写这么长的代码。好高兴。哈哈
- 歌词加载学习笔记
- Android---歌词加载
- 学习笔记--实现类似酷狗音乐歌词的效果
- 日语歌词学习+翻译
- 日语歌词学习+翻译
- 动态加载学习笔记
- C#winfrom播放器动态加载歌词
- 歌词迷API文档学习
- Linux 引导加载学习笔记
- tocmat类加载学习笔记
- unity学习笔记【场景加载】
- JVM类加载学习笔记
- iOS学习笔记:懒加载
- iOS懒加载学习笔记
- 温故知新-加载器学习笔记
- 歌词
- 歌词
- 歌词
- 关于oc中出现的typedef的用法/定义函数指针
- 在编译oc中protocol时出现的错误
- "this class is not key value coding-compliant for the key ..."问题的解决
- 关于Cannot assign to 'self' outside of a method in the init family解决方法
- 学习ios键盘和textfield之间操作体会
- 歌词加载学习笔记
- 在ios8中做的屏幕旋转功能
- 积累的 Android 开发各种开源库
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 封装实现一个自己的tabbar
- ios中strong和weak的解释理解
- duplicate symbols for architecture armv7解决办法
- 关于编程上的一些建议
- 关于block的一些理解