2015-10-20 94 views
1

我有一個活動(活動A),可以調用另一個從URL(視頻視頻)加載視頻的活動。當我回到活動A,我可以去活動B,我有一個代碼執行與HttpURLConnection的請求。問題是如果我去活動視頻並加載Videoview,請求活動B返回一個空響應。Android - Videoview URL HttpURLConnection

如果我更改活動視頻並刪除視頻視圖,它工作良好。

Image

活動視頻:

String urlVideo = getIntent().getStringExtra("URL_TRAILER");  
    Uri uri = Uri.parse(urlVideo); 
    videoView = (VideoView)findViewById(R.id.myvideoview);  
    MediaController mc = new MediaController(this); 
    mc.setAnchorView(videoView); 
    mc.setMediaPlayer(videoView); 
    videoView.setMediaController(mc); 
    videoView.setVideoURI(uri); 
    videoView.start(); 

HttpURLConnection的

 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
    conn.setDefaultUseCaches(false); 
    conn.setUseCaches(false); 
    conn.setReadTimeout(15000); 
    conn.setConnectTimeout(15000); 
    conn.setRequestMethod("POST"); 
    conn.setDoInput(true); 
    conn.setDoOutput(true); 

    int responseCode = conn.getResponseCode(); 

    if (responseCode == HttpsURLConnection.HTTP_OK) { 
     String line; 
     BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
     while ((line = br.readLine()) != null) { 
      response += line; 
     } 
    } else { 
     response = ""; 

    } 

回答

0

我找到了解決方案,使用的HttpClient和Htt的pPost而不是HttpURLConnection。

我不知道HttpURLConnection有什麼問題。