Android 如何在WebView中打开视频播放器?
我用Webview展示了一个WebApp。在这些页面中,我有一些视频链接(MP4、3GP…) 当我点击链接时,什么也没发生Android 如何在WebView中打开视频播放器?,android,video,webview,android-video-player,Android,Video,Webview,Android Video Player,我用Webview展示了一个WebApp。在这些页面中,我有一些视频链接(MP4、3GP…) 当我点击链接时,什么也没发生 public class luxgateway extends Activity { WebView myWebView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
public class luxgateway extends Activity {
WebView myWebView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setAllowFileAccess(true);
WebViewClient webViewClient = new MyWebViewClient();
myWebView.setWebViewClient(webViewClient);
myWebView.loadUrl("http://www.example.com/demo.html");
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".3gp")) {
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} else {
return super.shouldOverrideUrlLoading(view, url);
}
}
}
我在这台服务器上找到了这段代码的某些部分,但它对我没有帮助“
在这种情况下,我只限于3GP文件,但我不知道哪个扩展名将放在网站上
我在测试中尝试了这段代码,只是为了看看视频是否可以播放(或者视频播放器是否只从这段代码开始)
Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
view.getContext().startActivity(intent);
return true;
在这种情况下,视频只加载了DOW。我希望将示例交互作为webrowser。当我单击视频链接时,浏览器会询问我希望使用哪个播放机播放此视频。如果指定uri包含视频,您可能会更幸运:
Intent intent = new Intent(Intent.ACTION_VIEW) //I encourage using this instead of specifying the string "android.intent.action.VIEW"
intent.setDataAndType(Uri.parse(url), "video/3gpp");
view.getContext().startActivity(intent);
因为我们没有指定一个特定的包来处理上述意图,所以它被称为隐式意图。对于隐式意图,如果有多个包处理您指定的内容类型,您将被要求在它们之间进行选择。这将为您提供所需的行为
Intent intent = new Intent(Intent.ACTION_VIEW) //I encourage using this instead of specifying the string "android.intent.action.VIEW"
intent.setDataAndType(Uri.parse(url), "video/3gpp");
view.getContext().startActivity(intent);