0

https://player.vimeo.com/video/136004191/configエラーが発生している間にvimeoから実際のURLを取得しようとしています:

response code:405
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err: java.io.FileNotFoundException: https://player.vimeo.com/video/136004191/config
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
07-26 11:42:46.236 22054-22183/com.sample.samplevideoview W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:353)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at com.sample.samplevideoview.AsyncHttpClient$AsyncDataRequestHideDialog.doInBackground(AsyncHttpClient.java:287)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-26 11:42:46.237 22054-22183/com.sample.samplevideoview W/System.err:     at java.lang.Thread.run(Thread.java:818)
07-26 11:42:46.281 22054-22054/com.sample.samplevideoview E/MainActivity: Must implement the interface java.lang.NullPointerException: Attempt to invoke virtual method 'com.sample.samplevideoview.Request com.sample.samplevideoview.VimeoResponse.getRequest()' on a null object reference

コードは次のとおりです。

    private void getRealUrl(String videoId)
        {
            AsyncHttpClient mAsyncHttpClient = new AsyncHttpClient();
            HashMap<String, String> params = new HashMap<>();
            String url = "https://player.vimeo.com/video/" + videoId + "/config";

            mAsyncHttpClient.postWithStringData(MainActivity.this, TAG,
                    url, StringConstants.METHOD_GET, params,false,
                    new AsyncHttpClient.AsyncHttpResponseCallBack() {
                        @Override
                        public void onResponse(String response) {
                            Gson gson = new GsonBuilder().create();
                            VimeoResponse movie = gson.fromJson(response, VimeoResponse.class);

                        }
                    }
        );
        }
public class AsyncHttpClient {

    public interface AsyncHttpResponseCallBack {
        void onResponse(String response);
    }

    private Vector<Object> params;
    private static final String UTF_ENCODING = "UTF-8";

    private static final int CONTEXT_INDEX = 0;
    private static final int TAG_INDEX = 1;
    private static final int URL_INDEX = 2;
    private static final int PARAMS_STRING_INDEX = 3;
    private static final int RESPONSE_CALLBACK_INDEX = 4;
    private static final int REQUEST_METHOD_INDEX = 5;
    private static final int SHOW_PROGRESS_DIALOG_INDEX = 6;
public void postWithStringData(Context context, String TAG, String url, String method,
                                   HashMap<String, String> hashMapParams, boolean showDialog,
                                   AsyncHttpResponseCallBack asyncHttpResponseCallBack) {
        if (Utilities.isConnected(context)) {
            try {
                params = new Vector<>();
                params.insertElementAt(context, CONTEXT_INDEX);
                params.insertElementAt(TAG, TAG_INDEX);
                params.insertElementAt(url, URL_INDEX);
                params.insertElementAt(getPostDataString(hashMapParams), PARAMS_STRING_INDEX);
                params.insertElementAt(asyncHttpResponseCallBack, RESPONSE_CALLBACK_INDEX);
                params.insertElementAt(method, REQUEST_METHOD_INDEX);
                new AsyncDataRequestHideDialog(context).execute(params);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }
private class AsyncDataRequestHideDialog extends AsyncTask<Vector<Object>, Void, String> {

        AlertDialog mAlert;
        String TAG, url;
        String paramsString;
        AsyncHttpResponseCallBack asyncHttpResponseCallBack;
        Context context;

        String method;
        public AsyncDataRequestHideDialog(Context context) {
            // TODO Auto-generated constructor stub
            this.context = context;
        }

        @Override
        protected String doInBackground(Vector<Object>... params) {
            Vector<Object> requestParams = params[0];
            TAG = (String) requestParams.get(TAG_INDEX);
            url = (String) requestParams.get(URL_INDEX);
            paramsString = (String) requestParams.get(PARAMS_STRING_INDEX);
            asyncHttpResponseCallBack = (AsyncHttpResponseCallBack) requestParams.get(RESPONSE_CALLBACK_INDEX);
            method = (String) requestParams.get(REQUEST_METHOD_INDEX);

            String result = "";
            URL requestURL;
            StringBuffer response;

            try {
                requestURL = new URL(url);
                HttpURLConnection conn = (HttpURLConnection) requestURL.openConnection();
                conn.setReadTimeout(StringConstants.READ_TIMEOUT);
                conn.setConnectTimeout(StringConstants.CONNECTION_TIMEOUT);
                conn.setRequestMethod(method);
                conn.setDoInput(true);
                conn.setDoOutput(true);
                OutputStream os = conn.getOutputStream();
                BufferedWriter writer = new BufferedWriter(
                        new OutputStreamWriter(os, UTF_ENCODING));
                writer.write(paramsString);
                writer.flush();
                writer.close();
                os.close();
                String line;
                response = new StringBuffer();
                Log.d(TAG,"response code:"+conn.getResponseCode());
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                while ((line = br.readLine()) != null) {
                    response.append(line);
                }
                result = response.toString();
            } catch (SocketTimeoutException e1) {
                e1.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();

            } finally {
                Log.d(TAG, result);
                return result;
            }
        }

        // Overriding onPreExecute to initialize and show progress dialog
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }
        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);

            // If result is not null
            if (result != null) {
                try {
                    // Making a log just to make sure of data.
                    Log.e(TAG, result);
                    asyncHttpResponseCallBack.onResponse(result);
                } catch (Exception e) {
                    Log.e(TAG, "Must implement the interface " + e.toString());
                }
            } else {
                mAlert = Utilities.createAlertDialog(context, "Error",
                        StringConstants.DATA_ERROR);
            }
        }
    }

応答コード405を取得している間?どうした ?モバイルとデスクトップのブラウザで同じ URL が応答してきました。

4

2 に答える 2

1

Vimeo API と対話するには、公式のvimeo-networking Java/Android ライブラリを使用することを強くお勧めします。

ライブラリはすべてのネットワーク ロジックを処理し (ボイラープレートを作成する必要はありませんHttpURLConnection)、URI でビデオを取得するための呼び出しも提供します。

単一の動画をリクエストする方法は次のとおりです。基本的には次のようになります。

String uri = ...;// the video uri; if you have a Video, this is video.uri
VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
     @Override
     public void success(Video video) {
          // use the video
     }

     @Override
     public void failure(VimeoError error) {
          // voice the error
     }
});

Videoビデオを所有している場合は、ライブラリ内のオブジェクトからすぐに必要な情報にアクセスできます。必要なリンクにアクセスできる をvideo.files返すなどの情報。VideoFile

于 2016-07-27T18:56:14.417 に答える
0

単純なGET文字列リクエストOutputStreamBufferクラスで例外が発生していたため、コードに問題があるようです。この簡単なコードを試してください。私の側ではうまくいきます。

 @Override
            protected String doInBackground(Vector<Object>... params) {

                String result = "";
                url = "https://player.vimeo.com/video/136004191/config";

                try {

                    URL obj = new URL(url);

                    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

                    // optional default is GET
                    con.setRequestMethod("GET");
                    BufferedReader in = new BufferedReader(
                            new InputStreamReader(con.getInputStream()));
                    String inputLine;
                    StringBuffer response = new StringBuffer();

                    while ((inputLine = in.readLine()) != null) {
                        response.append(inputLine);
                    }
                    in.close();

                    //print result
                    System.out.println(response.toString());

                    result = response.toString();
                } catch (SocketTimeoutException e1) {
                    e1.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();

                } finally {
                    Log.d(TAG, result);
                    return result;
                }
            }
于 2016-07-26T08:12:40.180 に答える