0

YouTubeビデオへのリンクがあるWebページを開くアプリがあります。

私には2つの問題があります:

  1. リンクは m.youtube.com を正常に開きますが、ビデオは再生されません。オレンジ色で強調表示されるだけで、何も起こりません。

  2. YouTube アプリに読み込むオプションはありません。

何か案は?エミュにはフラッシュやYouTubeアプリがないことがわかっているので、エミュレータではなく私のギャラクシーS2でテストします。

あなたが命の恩人になる手助けをしてくれてありがとう!

これが私のコードです:

 package com.mytest;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.Window;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    public class mytestActivity extends Activity

    {

        final Activity activity = this;

        private WebView webview;


        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            // Check if the key event was the BACK key and if there's history
            if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
                webview.goBack();
                return true;
            }
            // If it wasn't the BACK key or there's no web page history, bubble up to the default
            // system behavior (probably exit the activity)
            return super.onKeyDown(keyCode, event);
        }

        @Override
        public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
                        setContentView(R.layout.main);

                        // Don't create another webview reference here,
                        // just use the one you declared at class level.
                        webview = (WebView) findViewById(R.id.webview);
                        webview.getSettings().setJavaScriptEnabled(true);
                        webview.getSettings().setPluginsEnabled(true);

                            webview.setWebChromeClient(new WebChromeClient() {
                            public void onProgressChanged(WebView view, int progress)
                            {
                                activity.setTitle("Loading...");
                                activity.setProgress(progress * 100);

                                if(progress == 100)
                                    activity.setTitle(R.string.app_name);
                            }
                        });

            webview.setWebViewClient(new WebViewClient() {
                @Override
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
                {
                    // Handle the error
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url)
                {
                    view.loadUrl(url);
                    return true;
                }


            });


            webview.loadUrl("http://mytesturl");

    }
4

1 に答える 1

1

私は WebViewClient にこれを持っており、YouTube ビデオをネイティブ アプリで開きます。

 @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains("youtube.com")){

            int indexStart = url.indexOf("?v=")+3;
            int indexEnd = url.indexOf("&", indexStart);
            if(indexEnd<indexStart)
                return false;
            String videoId = url.substring(indexStart,indexEnd);
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://"+videoId)));

            return true;
        }
        else
        {
            return false;
        }
    }
于 2012-01-18T19:28:12.537 に答える