IOS parsing lyrics lrc

Source: Internet
Author: User

IOS parsing lyrics lrc
Recently, I learned some things in the Process of playing a music player and wrote it down to share it. First of all, I want to analyze the lyrics. First, let's look at lrc. (If you don't stick a wiki, you may not be able to open the lyrics. Generally, this is the format. [minute: second. millisecond] lyrics 2. [minute: Second] lyrics 3. [minute: Second: millisecond] 1 of the lyrics is in the standard format. I will use the following example. The idea is to first obtain the entire lyric content, and then segment it by line feed. The content in each line is divided into two parts: time and content, extracted separately. -(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]) {nsange startrange = [item rangeOfString: @ "["]; NSLog (@ "% d", startrange. length, startrange. location); nsange 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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.