2011-09-17 4 views
0

私は自分のアプリを持っています。このページにはYouTubeのビデオへのリンクがあります。YouTubeビューの代わりにm.youtube.comへのWebviewリンク

私は2つの問題を抱えて:

  1. リンクオープンm.youtube.comの罰金をしかし動画は再生できません。オレンジ色で強調表示されても何も起こりません。

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

私はemuがフラッシュまたはYouTubeアプリケーションを持っていないことを知っているようにエミュレータよりも私の銀河S2のImテスト。

多くのお手伝いをしていただきありがとうございます。人生の節約になります!ここで

は私のコードです:

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"); 

    } 

答えて

1

は、私は私のWebViewClientでこれを持っており、それは、ユーチューブの動画をネイティブアプリ開きます

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