2012-10-23 5 views
15

현재 웹 사이트를 기반으로하는 Android 애플리케이션에서 작업하고 있습니다. iOS 응용 프로그램이 이미 존재하므로 유니 코드에 대한 일부 코드를 존중해야합니다.Android 웹보기에서 iframe 동영상이 전체 화면 모드로 전환되지 않습니다.

모든 것이 거의 완료되었지만 흥미로운 문제가 발견되었습니다. iframe 동영상 (Youtube, Dailymotion)이 포함 된 페이지의 webview (페이지가 표시되지 않아도 제어 할 수 없음)를 사용하면 ' 나는 플레이어의 버튼을 눌러도 전체 화면으로 이동하지 않습니다.

나는 이미 여기에서 발견 된 거의 모든 것을 시도했지만, 표시해야하는 페이지를 알고있는 앱만 참조합니다.

다음은 응용 프로그램의 webActivity 부분에 대한 코드입니다 : 어떤 도움

public class WebActivity extends Activity { 
    String targetURL = ""; 
    String title = ""; 
    WebView wv; 

    @Override 
    public void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); } 
    @Override 
    public void onPause() { super.onPause(); CookieSyncManager.getInstance().stopSync(); } 

    /** Called when the activity is first created. */ 
    @SuppressLint("SetJavaScriptEnabled") 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().requestFeature(Window.FEATURE_PROGRESS); 
     //getWindow().requestFeature(Window.FEATURE_NO_TITLE); 
     CookieSyncManager.createInstance(getApplicationContext()); 
     CookieSyncManager.getInstance().startSync(); 
     CookieManager.getInstance().setAcceptCookie(true); 
     /** 
     * TODO: WebView Cookie management. 
     * Right now, a cookie is hardcoded here into the WebView instead of getting it from the API called by HttpClient when retrieving the JSON. 
     * Need to make things cleaner. 
     */ 
     CookieManager.getInstance().setCookie("http://www.blabla.fr/mobile/","gbapi=1; Domain=.www.blabla.fr"); 
     /** 
     * Get parameters 
     */ 
     Bundle b = getIntent().getExtras(); 
     if(b != null) 
     { 
      targetURL = b.getString("url"); 
      title = b.getString("title"); 
     } 

     setTitle(title); 
     setContentView(R.layout.activity_webview); 

     wv = (WebView) findViewById(R.id.webview); 

     WebSettings wvSettings = wv.getSettings(); 

     // WebView options 
     wvSettings.setDefaultTextEncodingName("utf-8"); 
     wvSettings.setJavaScriptEnabled(true); 
     wvSettings.setPluginState(PluginState.ON); 
     wvSettings.setJavaScriptCanOpenWindowsAutomatically(true); 
     wvSettings.setBuiltInZoomControls(true); 
     final Activity activity = this; 
     wv.setWebChromeClient(new WebChromeClient() { 
      public void onProgressChanged(WebView view, int progress) { 
       activity.setProgress(progress * 100); 
      } 
     }); 

     wv.setWebViewClient(new WebViewClient() { 
      public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
       Toast.makeText(activity, "Oh snap! " + description, Toast.LENGTH_SHORT).show(); 
      } 
     }); 

     wv.loadUrl(targetURL); 
    } 
} 

감사합니다.

답변

2

onHideCustomView뿐만 아니라 onShowCustomView의 두 버전 (이 콜백의 새 버전은 API 레벨 14에서 도입되었습니다)을 처리하는 사용자 정의 WebChromeClient를 만들어야합니다. 근본적으로 일어날 일은 비디오를 전체 화면으로 재생하려고하면 VideoView의 변형 일 수 있습니다. 이것을 전체 화면 FrameLayout에 첨부하고 레이아웃 계층의 루트에 붙여서 전체 화면을 오버레이해야합니다. 작업이 완료되면 다시 제거해야합니다. 여기

은 그래서 첨부 할 수 있도록 내가 활동과 밀접하게 커플로했다가 진정으로 전체 화면 만들기 위해, 내가 조각 내에서이 일을하고 비디오

private class DerpChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener { 
    //@Override 
    public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) { 
     log.warn("onShowCustomView"); 
     showCustomView(view, callback); 
    } 

    private View mVideoProgressView; 

    @Override 
    public void onHideCustomView() { 
     super.onHideCustomView(); 

     activity.removeFullscreenView(); 
     webView.setVisibility(View.VISIBLE); 

     try { 
      mCustomViewCallback.onCustomViewHidden(); 
     } catch (NullPointerException npe) { 
      // occasionally Android likes to freak out and throw an unhandled NPE if it can't play the video 
      // therefore we are not going to do anything but eat this exception so it fails gracefully 
     } 

     mCustomView = null; 
     mVideoView = null; 
    } 

    @Override 
    public void onShowCustomView(View view, CustomViewCallback callback) { 
     super.onShowCustomView(view, callback); 
     log.warn("onShowCustomView"); 
     showCustomView(view, callback); 
    } 

    private void showCustomView(View view, CustomViewCallback callback) { 
     if (mCustomView != null) { 
      callback.onCustomViewHidden(); 
      return; 
     } 

     mCustomView = view; 
     mCustomViewCallback = callback; 
     webView.setVisibility(View.GONE); 

     if (view instanceof FrameLayout) { 
      if (((FrameLayout)view).getFocusedChild() instanceof VideoView) { 
       mVideoView = (VideoView)((FrameLayout)view).getFocusedChild(); 
      } 
     } 

     view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); 
     view.setBackgroundColor(Color.BLACK); 
     activity.displayFullscreenView(view); 
    } 

    @Override 
    public boolean onConsoleMessage(ConsoleMessage cm) { 
     log.warn("Console Message: " + cm.message() + " on line " + cm.lineNumber() + " of " + cm.sourceId()); 
     return super.onConsoleMessage(cm); 
    } 

    @Override 
    public void onProgressChanged(WebView view, int newProgress) { 
     super.onProgressChanged(view, newProgress); 

     if (newProgress < 100) { 
      if (loadingProgress.getVisibility() == ProgressBar.GONE) { 
       loadingProgress.setVisibility(ProgressBar.VISIBLE); 
      } 
      loadingProgress.setProgress(newProgress); 
     } else if (newProgress >= 100) { 
      loadingProgress.setVisibility(ProgressBar.GONE); 
     } 
    } 

    @Override 
    public View getVideoLoadingProgressView() { 
     if (mVideoProgressView == null) { 
      LayoutInflater inflater = LayoutInflater.from(KnowledgeBaseFragment.this.getActivity().getApplicationContext()); 
      mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null); 
     } 

     return mVideoProgressView; 
    } 

    @Override 
    public boolean onError(MediaPlayer mp, int what, int extra) { 
     // TODO Auto-generated method stub 
     return false; 
    } 

    @Override 
    public void onCompletion(MediaPlayer mp) { 
     this.onHideCustomView(); 
    } 
} 

음을 연주하기 위해 사용하고 버전입니다 프래그먼트뿐만 아니라 전체 뷰 계층 구조의 루트에있는 FrameLayout. WebView and HTML5 <video>

+1

내가 몇 달이 코드에보고되지 않은 : 여기 당신처럼 또 다른 질문입니다

@Override public void displayFullscreenView(View customView) { parentLayout.addView(customView); this.customView = customView; } @Override public void removeFullscreenView() { if (customView != null) { customView.setVisibility(View.GONE); parentLayout.removeView(customView); } customView = null; } 

: 여기

그 기능입니다. 반쯤 완료된 수술과 남은 변수가 많습니다. ><이것을 정리할 시간. – MattC

+1

감사합니다. 코드를 약간 수정해야했지만 사용할 수있었습니다. – Pascal

관련 문제