iOS lyrics parsing

Source: Internet
Author: User

Finally, the lyrics have been solved, share to everyone.

First I define a method that passes in the name of the lyrics and returns a dictionary with the ":" Split timestamp, and the value is the lyrics of the current line.

1-(nsmutabledictionary*) MUSICLRC: (nsstring*) Musicname2 {3     4     //Initialize a dictionary5Nsmutabledictionary *musiclrcdictionary=[[nsmutabledictionary alloc]initwithcapacity: -];6     //load lyrics to memory7NSString *strmusicurl=[[nsbundle mainbundle]pathforresource:musicname OfType:@"LRC"];8NSString *strlrcku=[NSString stringwithcontentsoffile:strmusicurl encoding:nsutf8stringencoding Error:nil];9     //split the file into an array in each unit of action .TenNsarray *strlinearray=[strlrcku componentsseparatedbystring:@"\ n"]; One     //Ann Reads lyrics lyrics A      for(intI=0; I<[strlinearray Count]; i++) { -         //split the time and lyrics -Nsarray *linecomponents=[[strlinearray Objectatindex:i] componentsseparatedbystring:@"]"]; the         //take out the time of each line note that some lyrics are reused, so there will be multiple points in time -          for(intn=0; N<[linecomponents Count]; n++) { -NSString *strkutimer =Linecomponents[n]; -             if([Strkutimer length]==9) { +                 //Remove ":" and "." Symbol to compare whether it's the time we need -NSString *str1=[strkutimer Substringwithrange:nsmakerange (3,1)]; +NSString *str2=[strkutimer Substringwithrange:nsmakerange (6,1)]; A                 if([str1 isequaltostring:@":"]&AMP;&AMP;[STR2 isequaltostring:@"."]) { at                     //put time and lyrics in two strings temporarily -NSString *linetimer=[[linecomponents Objectatindex:n] Substringwithrange:nsmakerange (1,5)]; -NSString *linestr=[linecomponents objectatindex: ([linecomponents count]-1)]; -                     //take time as key, lyrics as value, put in dictionary - [Musiclrcdictionary setobject:linestr Forkey:linetimer]; -                 } in             } -         } to     } +     //return the entire dictionary here -     returnmusiclrcdictionary; the      *}

The complete code has a managed address on my GitHub: Https://github.com/qisedao0215/audioPlay

  

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.