Puoi utilizzare iframe come descritto in https://developers.google.com/youtube/iframe_api_reference
Non sto seguendo esattamente i consigli di Google, ma questo è il codice che sto usando e funziona bene
public class CWebVideoView {
private String url;
private Context context;
private WebView webview;
private static final String HTML_TEMPLATE = "webvideo.html";
public CWebVideoView(Context context, WebView webview) {
this.webview = webview;
this.context = context;
webview.setBackgroundColor(0);
webview.getSettings().setJavaScriptEnabled(true);
}
public void load(String url){
this.url = url;
String data = readFromfile(HTML_TEMPLATE, context);
data = data.replace("%1", url);
webview.loadData(data, "text/html", "UTF-8");
}
public String readFromfile(String fileName, Context context) {
StringBuilder returnString = new StringBuilder();
InputStream fIn = null;
InputStreamReader isr = null;
BufferedReader input = null;
try {
fIn = context.getResources().getAssets().open(fileName, Context.MODE_WORLD_READABLE);
isr = new InputStreamReader(fIn);
input = new BufferedReader(isr);
String line = "";
while ((line = input.readLine()) != null) {
returnString.append(line);
}
} catch (Exception e) {
e.getMessage();
} finally {
try {
if (isr != null)
isr.close();
if (fIn != null)
fIn.close();
if (input != null)
input.close();
} catch (Exception e2) {
e2.getMessage();
}
}
return returnString.toString();
}
public void reload() {
if (url!=null){
load(url);
}
}
}
in / assets ho un file chiamato webvideo.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
iframe { border: 0; position:fixed; width:100%; height:100%; bgcolor="#000000"; }
body { margin: 0; bgcolor="#000000"; }
</style>
</head>
<body>
<iframe src="%1" frameborder="0" allowfullscreen></iframe>
</body>
</html>
e ora definisco una visualizzazione web all'interno del mio layout principale
<WebView
android:id="@+id/video"
android:visibility="gone"
android:background="#000000"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
e utilizzo CWebVideoView all'interno della mia attività
videoView = (WebView) view.findViewById(R.id.video);
videoView.setVisibility(View.VISIBLE);
cWebVideoView = new CWebVideoView(context, videoView);
cWebVideoView.load(url);