Android webview show youtube.com/tv video in full screen

I am making an application to display youtube.com/tv on TVs. It has a simple and enjoyable layout, and also has some nice features, such as pairing and controlling it using a smartphone. So .. I use webview to get url: youtube.com/tv

Everything works fine, besides, I would like it to automatically show in full screen when vid is selected.

Usually I found all my answers in a search (here), but this is complicated.

I would like everything to happen in a web review. Should it be possible? Or do I need to start a new intention or create a new videoview.java class to call exks. videoview.xml? Not really sure about it .. The reason I ask is that when vid starts up, youtube.com/tv automatically plays on like a playlist, I would like to save it that way.

I found some HTML5 fullscreen document in http://developer.android.com/reference/android/webkit/WebChromeClient.html#onShowCustomView(android.view.View , android.webkit.WebChromeClient.CustomViewCallback) about how it done, but still confused, is this the way? Using:

public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) 

and

 public void onHideCustomView () 

Here is my main TV.java so far. Please be careful as I am very new to this.

 @SuppressLint("SetJavaScriptEnabled") public class Tv extends Activity { WebView web; @Override public void onCreate(Bundle savedInstanceState) { //Transparent actionBar Only option menu available... requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(null); setDisplayShowHomeEnabled(false); setTitleShowHomeEnabled(); getActionBar().setDisplayShowHomeEnabled(false); getActionBar().setDisplayShowTitleEnabled(false); super.onCreate(savedInstanceState); setContentView(R.layout.webview); // webview id web = (WebView) findViewById(R.id.webview); //webchromeclient web.setWebChromeClient(new WebChromeClient()); //hide search bar web.setWebViewClient(new myWebClient()); //Enable javascript web.getSettings().setJavaScriptEnabled(true); web.getSettings().setPluginState(PluginState.ON); //Scale video controls web.setInitialScale(150); // Test //web.getSettings().setLoadWithOverviewMode(true); //web.getSettings().setUseWideViewPort(true); //web.setVerticalScrollbarOverlay(true); //web.getSettings().setAllowFileAccess(true); //Load url web.loadUrl("http://www.youtube.com/tv"); //Load file from assets NB: Missing "S" is correct // web.loadUrl("file:///android_asset/yt.html"); } //Fullscreen public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { } public void onHideCustomView () { } //End fullscreen private void setTitleShowHomeEnabled() { } private void setDisplayShowHomeEnabled(boolean b) { } public class myWebClient extends WebViewClient { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } // To handle "Back" key press event for WebView to go back to previous screen. @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) { web.goBack(); return true; } return super.onKeyDown(keyCode, event); } // Ask if user wants to exit @Override public void onBackPressed() { new AlertDialog.Builder(this) .setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //Tv.this.finish(); android.os.Process.killProcess(android.os.Process.myPid()); } }) .setNegativeButton("No", null) .show(); } //Option menu public class SimpleOptionMenu extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webview); } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.text1: AlertDialog alertDialog = new AlertDialog.Builder(this).create(); //Read Update alertDialog.setTitle("Information"); alertDialog.setMessage("In order to log in to your account and activate the use of your smart phone, please select: -Sign in & settings- -> -Sign in- in the left menu, write down the activation code, and then click on -Activate- in this menu. Have a happy tube :) "); alertDialog.setButton("Continue..", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alertDialog.show(); break; case R.id.text2: Intent intent = new Intent(this, GetActivation.class); this.startActivity(intent); break; //Exit case R.id.text3: android.os.Process.killProcess(android.os.Process.myPid()); // <- Complete kill //Tv.this.finish(); <-Dosent kill totally return true; default: return false; } return true; } } 
+4
source share

All Articles