The song name and artist name are garbled
Mediapickeractivity. Java adds the changestringencode method to convert string encoding:
Publicstatic string changestringencode (string content)
{
If (Java. NiO. charset. charset. forname ("gb2312"). newencoder (). canencode (content ))
{
// Log. D (TAG, "gb2312 ...");
}
Elseif (Java. NiO. charset. charset. forname ("ISO-8859-1"). newencoder (). canencode (content ))
{
// Log. D (TAG, "ISO-8859-1 ...");
Try
{
Content = new string (content. getbytes ("ISO-8859-1"), "GBK ");
}
Catch (unsupportedencodingexception E)
{
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Else if (Java. NiO. charset. charset. forname ("GBK"). newencoder (). canencode (content ))
{
// Log. D (TAG, "GBK ...");
}
Elseif (Java. NiO. charset. charset. forname ("UTF-8"). newencoder (). canencode (content ))
{
Try {
Content = new string (content. getbytes ("UTF-8"), "GBK ");
}
Catch (unsupportedencodingexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
// Log. D (TAG, "UTF-8 ...");
}
Else if (Java. NiO. charset. charset. forname ("UTF-16"). newencoder (). canencode (content ))
{
// Log. D (TAG, "UTF-16 ...");
}
Return content;
}
Then modify the title name, album name, and artist name in BindView:
// String name = cursor. getstring (mtitleidx );
String name =Changestringencode(Cursor. getstring (mtitleidx ));
// Name = cursor. getstring (malbumidx );
Name =Changestringencode(Cursor. getstring (malbumidx ));
// Name = cursor. getstring (martistidx );
Name =Changestringencode(Cursor. getstring (martistidx ));
2. garbled characters are displayed after language switching
In a multi-language environment, the lyrics of Chinese songs are normally displayed in the Chinese environment, and garbled characters may occur when you switch to other languages such as French and Arabic. The modification points are as follows:
Set
Filereader = new bufferedreader (New inputstreamreader (connection. getinputstream (), lyricslocale. deflocale2charset ()));
Change
Fileinputstreamfcm = new fileinputstream (lrcfile );
Bufferedinputstreamin = new bufferedinputstream (FCM );
In. Mark (4 );
Byte [] first3bytes = new byte [3];
N. Read (first3bytes );
In. Reset ();
If (first3bytes [0] = (byte) 0xef & first3bytes [1] = (byte) 0xbb & first3bytes [2] = (byte) 0xbf) {// UTF-8
Filereader = new bufferedreader (newinputstreamreader (New fileinputstream (lrcfile), "UTF-8 "));
}
Elseif (first3bytes [0] = (byte) 0xff & first3bytes [1] = (byte) 0xfe) {// Unicode
Filereader = new bufferedreader (newinputstreamreader (New fileinputstream (lrcfile), "Unicode "));
}
Elseif (first3bytes [0] = (byte) 0xfe & first3bytes [1] = (byte) 0xff) {// utf-16be
Filereader = new bufferedreader (newinputstreamreader (New fileinputstream (lrcfile), "utf-16be "));
}
Elseif (first3bytes [0] = (byte) 0xff & first3bytes [1] = (byte) 0xff) {// utf-16le
Filereader = new bufferedreader (newinputstreamreader (New fileinputstream (lrcfile), "utf-16le "));
}
Else {// GBK
Filereader = new bufferedreader (newinputstreamreader (New fileinputstream (lrcfile), "GBK "));
}