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>
webViewでyoutubeを読み込む代わりにyoutube apiを使用してください。 –
Webviewの代わりにYouTube Android Player APIを使用する方が良いでしょう。フルスクリーンと他のコントロールを扱うことができます。このドキュメントを確認するhttps://developers.google.com/youtube/android/player/ –
YouTube SDKを使用することができます –