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:@":"]&&[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