Saturday, January 21, 2012

About URLConnection

Today is Chinese New Year.
The market is so concerned about the comments after the release, so I can not support.

Yes, just released a new version.

The main modification is related to changes in layout and menu display album. Once, several bug fixes.

We also fixed with respect to the subject and then also the URL connection.
Changed the way I say the right one before rather than fixed.

URL connection handling has been changed about two weeks ago.
This is a fix for concurrent communication with SSL, the scope of my testing was working well.
However, commenting on reports that the market is gets stuck out.

Specifically, the following has been changed.

Two weeks ago between :
                connection = (HttpURLConnection) url.openConnection();
                int responseCode = connection.getResponseCode();

                if (responseCode == 200) {
                    in = connection.getInputStream();

After the change:
synchronized SchemeRegistry getRegistry(){
        if(mSchemeRegistry == null){
            mSchemeRegistry = new SchemeRegistry();
            // http scheme
            mSchemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            // https scheme
            mSchemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
        return mSchemeRegistry;
    synchronized BasicHttpParams getHttpParams(){
        if(mParams == null){
            mParams = new BasicHttpParams();
            mParams.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
            //mParams.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
            mParams.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
            HttpConnectionParams.setSocketBufferSize(mParams, SOCK_BUFSIZE); 
            HttpConnectionParams.setSoTimeout(mParams, SOCKET_TIMEOUT);
            HttpConnectionParams.setConnectionTimeout(mParams, SOCKET_TIMEOUT); 
            HttpProtocolParams.setContentCharset(mParams, "UTF-8"); 
            HttpProtocolParams.setVersion(mParams, HttpVersion.HTTP_1_1);
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            BasicScheme basicAuth = new BasicScheme();
            mHttpContext = new BasicHttpContext();
            mHttpContext.setAttribute("http.auth.credentials-provider", credentialsProvider);
            mHttpContext.setAttribute("preemptive-auth", basicAuth);
        return mParams;

//implement here.
                m = new ThreadSafeClientConnManager(getHttpParams(), getRegistry());
                DefaultHttpClient client = new DefaultHttpClient(cm, getHttpParams());
                HttpGet get = new HttpGet(url.toString());
                get.setHeader("Host", url.getHost());
                get.setHeader("User-Agent", "Android-JustPlayer");
                HttpResponse httpResponse = client.execute(get,mHttpContext);
                if (httpResponse != null
                        && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    HttpEntity httpEntity = httpResponse.getEntity();
                    in = httpEntity.getContent();

first approach is generic, it is very easy to connect was just passing the URL. However, some users can not Basic authentication, it was reported that an SSL connection or not. And now the more unstable the connection request.

So, we changed the usage of HttpClient. This is to work look, may not be able to connect port 8080, and in case the connection itself fails.
These are must be supported patient.

But for those in need now, first aid anyway
Has been changed as follows.

//new code
//old code

Try to look at it for a while.


  1. I can't change play view after the last update, and scrolling doesn't work in the equalizer.

  2. Equalizer has been moved to the context menu.