2011-11-24 151 views
0

我的應用程序使用WebView顯示網頁。我希望用戶能夠點擊視頻鏈接,並以橫向模式播放視頻。我現在在哪裏,視頻甚至不播放?WebView shouldOverrideUrlLoading Wont播放視頻

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.mnwv_main);  

myWebView = (WebView) findViewById(R.id.webview); 
myWebView.getSettings().setJavaScriptEnabled(true); 
myWebView.getSettings().setPluginsEnabled(true);  

myWebView.setWebViewClient(new WebViewClient());  
myWebView.loadUrl("http://www.meanwhileinwv.com"); 

}  
public boolean shouldOverrideUrlLoading (WebView view, String url) { 
if (url.endsWith(".mp4")){ 
    Intent in = new Intent (Intent.ACTION_VIEW , Uri.parse(url)); 
    startActivity(in); 
    return true; 
} 
else 
    return false; 
} 

回答

0

更改此:

... 

myWebView.setWebViewClient(new WebViewClient());  
myWebView.loadUrl("http://www.meanwhileinwv.com"); 

}  
public boolean shouldOverrideUrlLoading (WebView view, String url) { 
if (url.endsWith(".mp4")){ 
    Intent in = new Intent (Intent.ACTION_VIEW , Uri.parse(url)); 
    startActivity(in); 
    return true; 
} 
else 
    return false; 
} 

與此:

... 

myWebView.setWebViewClient(new WebViewClient() { 
    @Override 
    public boolean shouldOverrideUrlLoading (WebView view, String url) { 
     if (url.endsWith(".mp4")){ 
      Intent in = new Intent (Intent.ACTION_VIEW , Uri.parse(url)); 
      startActivity(in); 
      return true; 
     } 
     else 
      return false; 
     } 

});  
myWebView.loadUrl("http://www.meanwhileinwv.com"); 

}  
+0

仍然給了我同樣的效果.. – comead