iOS歌词解析

摘要:
我终于解开了歌词并与你分享。首先,我定义了一个传递歌词名称并返回字典的方法。键是用“:”分隔的时间戳,值是当前行的歌词。

  好不容易吧歌词解出来了,分享给大家。

  首先我定义了一个方法,把歌词的名字传进去,返回一个字典,key是以“:”分割的时间戳,值是当前行的歌词。

 

 1 -(NSMutableDictionary*)musicLrc:(NSString*)musicName
 2 {
 3     
 4     //    初始化一个字典
 5     NSMutableDictionary *musicLrcDictionary=[[NSMutableDictionary alloc]initWithCapacity:20];
 6     //    加载歌词到内存
 7     NSString *strMusicUrl=[[NSBundle mainBundle]pathForResource:musicName ofType:@"lrc"];
 8     NSString *strLrcKu=[NSString stringWithContentsOfFile:strMusicUrl encoding:NSUTF8StringEncoding error:nil];
 9     //    把文件安行分割,以每行为单位放入数组
10     NSArray *strlineArray=[strLrcKu componentsSeparatedByString:@"
"];
11     //    安行读取歌词歌词
12     for (int i=0; i<[strlineArray count]; i++) {
13         //      将时间和歌词分割
14         NSArray *lineComponents=[[strlineArray objectAtIndex:i] componentsSeparatedByString:@"]"];
15         //        取出每行的时间  注意有些歌词是重复使用的,所以会有多个时间点
16         for (int n=0; n<[lineComponents count]; n++) {
17             NSString *strKuTimer = lineComponents[n];
18             if ([strKuTimer length]==9) {
19                 //    取出“:”和“.”符号来对比,是否是我们所需要的时间
20                 NSString *str1=[strKuTimer substringWithRange:NSMakeRange(3, 1)];
21                 NSString *str2=[strKuTimer substringWithRange:NSMakeRange(6, 1)];
22                 if ([str1 isEqualToString:@":"]&&[str2 isEqualToString:@"."]) {
23                     //    将时间和歌词暂时放在两个字符串里
24                     NSString *lineTimer=[[lineComponents objectAtIndex:n] substringWithRange:NSMakeRange(1, 5)];
25                     NSString *lineStr=[lineComponents objectAtIndex:([lineComponents count]-1)];
26                     //    以时间为key,歌词为值,放入字典中
27                     [musicLrcDictionary setObject:lineStr forKey:lineTimer];
28                 }
29             }
30         }
31     }
32     //    在这里返回整个字典
33     return musicLrcDictionary;
34     
35 }

  完整的代码在我的github上有托管地址是:https://github.com/qisedao0215/audioPlay

  

免责声明:文章转载自《iOS歌词解析》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇基于yolo3自定义训练数据(三)使用imgaug扩大数据集一个人工智能项目里的中文分词方案下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

ios文件读取

     /*      *  @brief沙盒下的各种文件      */ - (void)getPaths {     /**      *  @brief获取沙盒的路径      */          NSString * HomeDirectory = NSHomeDirectory();          NSLog(@"%@",HomeDir...

iOS开发时间戳与时间,时区的转换,汉字与UTF8,16进制的转换

原文:http://blog.sina.com.cn/s/blog_68661bd80101njdo.html //获取当前系统的时间戳+(long)getTimeSp{    long time;    NSDate *fromdate=[NSDate date];    time=(long)[fromdate timeIntervalSince197...

OC基础 文件管理

OC基础  文件管理 1.文件管理类NSFileManager对象的创建:   NSFileManager *fm = [NSFileManager defaultManager]; 2.文件操作: (1)遍历查看目录下的文件:   a.遍历查看目录下的文件:contentsOfDirectorAtPath:(NSString *)path error:(...

AFNetworking的详细解析

AFNetworking serializer 分析 AFNetworkResponse.png 1. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; 所有的网络请求,均有manager发起 2. 需要注意的是,默认提交...

IOS开发NSString与int和float的相互转换以及字符串拼接、NSString、NSData、char* 类型之间的转换

一、NSString与int和float的相互转换 NSString *tempA = @"123"; NSString *tempB = @"456"; 1.字符串拼接 NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB]; 2.字符转intint intStr...

iOS开发:通过经纬度获得城市、省份等信息

  iOS系统自带定位,用CLLocationManager就可以轻松的实现定位的操作,获得的是一组经纬度,当然,也可以根据给出的经纬度获取相应的省份、城市、街道等信息,下面就看一个根据经纬度获得城市的demo:         因为获取经纬度需要CLLocationManager类,而这个类包含在CoreLocation框架中,获取城市信息需要mapKi...