Je crains que vous ne puissiez pas faire cela jusqu'à ce que le lecteur vidéo Android native commence à supporter cela. Mais il existe une solution de contournement très sale pour lancer l'application YouTube.
WebView w = new WebView(this);
w.getSettings().setJavaScriptEnabled(true);
w.getSettings().setBuiltInZoomControls(true);
//need to to change the user-agent to fool server
w.getSettings().setUserAgentString("Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
w.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
//get the URL of the touched anchor tag
WebView.HitTestResult hr = ((WebView)v).getHitTestResult();
String str = hr.getExtra();
//check if it is the URL of the thumbnail of the video
//which looks like
//http://i.ytimg.com/vi/<VIDEOID>/hqdefault.jpg?w=160&h=96&sigh=7exXMTRY7yiZm4hS4V_f9uVO-GU
if(str!=null && str.startsWith("http://i.ytimg.com/vi/")){
String videoId = str.split("\\/")[4];
//Everything is in place, now launch the activity
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" +videoId));
v.getContext().startActivity(i);
return true;
}
return false;
}
}
w.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
);
w.loadUrl("http://m.youtube.com");
cela a très bien fonctionné, vous pouvez obtenir l'ID vidéo comme ceci Uri uri = Uri.parse (url); String vid = uri.getQueryParameter ("v"); – schwiz