IOS 解析歌词lrc
2014-09-13 16:31
671 查看
最近在捣鼓音乐播放器,过程中学到了一些东西,写下来分享一下,首先是歌词的解析
首先我们看看lrc(不贴维基了怕打不开
歌词文件一般是这样的格式
1.[分钟:秒.毫秒] 歌词
2. [分钟:秒] 歌词
3. [分钟:秒:毫秒] 歌词
其中1是标准格式,下面我就一种为例。
思路是先获取整个歌词内容,再按换行分段,对每一行中的内容,分为两部分,时间和内容,分别提取。
-(void)parselyric { NSString *path = [[NSBundle mainBundle]pathForResource:_lab_title.text ofType:@"lrc"]; //if lyric file exits if ([path length]) { //get the lyric string NSString *lyc = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; //init _musictime = [[NSMutableArray alloc]init]; _lyrics = [[NSMutableArray alloc]init]; _t = [[NSMutableArray alloc]init]; NSArray *arr = [lyc componentsSeparatedByString:@"\n"]; for (NSString *item in arr) { //if item is not empty if ([item length]) { NSRange startrange = [item rangeOfString:@"["]; NSLog(@"%d%d",startrange.length,startrange.location); NSRange stoprange = [item rangeOfString:@"]"]; NSString *content = [item substringWithRange:NSMakeRange(startrange.location+1, stoprange.location-startrange.location-1)]; NSLog(@"%d",[item length]); //the music time format is mm.ss.xx such as 00:03.84 if ([content length] == 8) { NSString *minute = [content substringWithRange:NSMakeRange(0, 2)]; NSString *second = [content substringWithRange:NSMakeRange(3, 2)]; NSString *mm = [content substringWithRange:NSMakeRange(6, 2)]; NSString *time = [NSString stringWithFormat:@"%@:%@.%@",minute,second,mm]; NSNumber *total =[NSNumber numberWithInteger:[minute integerValue] * 60 + [second integerValue]]; [_t addObject:total]; NSString *lyric = [item substringFromIndex:10]; [_musictime addObject:time]; [_lyrics addObject:lyric]; } } } } else _lyrics = nil; }
这里我只处理里标准格式的歌词,其它格式也可用类似方法处理。
相关文章推荐
- ios开发学习--歌词处理--解析lrc文件
- 正则表达式练习: android 歌词解析lrc 转 txt 代码
- 歌词文件LRC的解析,可用于音乐播放器实现歌词同步操作
- Android自定义View来实现解析lrc歌词并同步滚动、上下拖动、缩放歌词的功能[转]
- JavaScript解析lrc文件音乐歌词
- C语言 LRC歌词文件解析
- MP3制作之LRC歌词文件解析(附:源代码)
- iOS歌词解析
- lrc 歌词解析项目
- JavaScript解析lrc文件音乐歌词
- lrc歌词解析(正则表达式)与歌词卡拉ok显示的思路
- ios开发学习- 简易音乐播放器2 (基于iPhone4s屏幕尺寸)-- 歌词解析--plist文件应用--imageNamed图片加载耗内存
- 我的Android进阶之旅------>Android自定义View来实现解析lrc歌词并同步滚动、上下拖动、缩放歌词的功能
- C语言 解析lrc歌词文件
- 正则表达式练习: android 歌词解析lrc 转 txt 代码
- Java LRC 歌词解析
- 如何用js完美的解析lrc歌词
- Java使用正则表达式解析LRC歌词文件
- JavaScript解析lrc文件音乐歌词
- C语言 解析lrc歌词文件