The song name and artist name are garbled

Source: Internet
Author: User
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 "));

}

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.