android webview全屏显示youtube.com/tv视频

时间:2012-12-12 18:16:53

标签: android webview youtube fullscreen

我正在制作一个应用程序,用于在电视机上显示youtube.com/tv。 它有一个简单而漂亮的布局,它还有一些很好的功能,如配对和通过智能手机控制它。 所以.. 我使用webview获取网址:youtube.com/tv

一切正常,exept我希望在选择vid时全屏自动显示。

通常我找到了所有答案,(这里),但这个很难。

我希望所有这些都发生在webview中。那应该是可能的吗?或者我是否需要启动新的意图,或者创建一个新类videoview.java来调用eks。 videoview.xml?真的不确定这个.. 我问的原因是,当vid启动时,youtube.com / tv会像播放列表一样自动播放,很想保持这种状态。

我在http://developer.android.com/reference/android/webkit/WebChromeClient.html#onShowCustomView(android.view.View,android.webkit.WebChromeClient.CustomViewCallback上找到了一些关于HTML5全屏的文档,关于如何做到但仍然困惑。这是要走的路吗? 使用:

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

public void onHideCustomView ()

这是我的主要TV.java直到现在。请保持温柔,因为我对这些东西很新。

@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;
    }
}

0 个答案:

没有答案