0
我有一个Youtube Webview及其工作良好。 现在我想添加一个选项,以在Youtube官方应用程序中以全屏方式播放视频。如何添加选项在youTube webiew中播放全屏视频
如何添加选项以全屏播放视频?
public class MainActivity extends AppCompatActivity {
WebView wb;
TextView tv;
private boolean exit = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activty_main);
wb = (WebView) findViewById(R.id.web);
tv = (TextView) findViewById(R.id.tv);
checkConnection();
}
protected boolean isonline() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
return true;
} else {
return false;
}
}
这是我的Webview设置,当我在手机上启动应用程序时,它不显示全屏播放选项。
private void checkConnection() {
if (isonline()) {
Toast.makeText(MainActivity.this, "You are connented to Internet",
Toast.LENGTH_SHORT).show();
wb.loadUrl("https://www.youtube.com/?gl=IN");
WebSettings webSettings = wb.getSettings();
webSettings.setJavaScriptEnabled(true);
wb.setWebViewClient(new WebViewClient());
} else {
Toast.makeText(this, "You r not connected to Internet",
Toast.LENGTH_SHORT).show();
tv.setText("Can't Connected to the Server. \n Please Check your
Internet Connection");
}
}
@Override
public void onBackPressed() {
if (wb.canGoBack()) {
wb.goBack();
} else {
if (exit) {
finish();
} else {
Toast.makeText(this, "Press again to exit",
Toast.LENGTH_SHORT).show();
}
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
exit = false;
}
}, 2000);
exit = true;
}
}
这是我的布局文件
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:id="@+id/web"
tools:ignore="RtlCompat">
</WebView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:layout_marginTop="200dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="18sp" />
</RelativeLayout>
使用YouTube的API,而不是加载YouTube的webView –
如果您使用YouTube Android播放器API而不是Webview将会更好。您可以处理全屏和其他控制。检查此文档https://developers.google.com/youtube/android/player/ –
您可以使用youtube SDK – 2017-10-10 11:49:55