2013-04-09 29 views
10
public class MainActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     WebView wv=(WebView)findViewById(R.id.webView1); 

     wv.getSettings().setJavaScriptEnabled(true); 
     wv.getSettings().setAppCacheEnabled(true); 
     wv.getSettings().setDomStorageEnabled(true); 

     // how plugin is enabled change in API 8 
     if (Build.VERSION.SDK_INT < 8) { 
      wv.getSettings().setPluginsEnabled(true); 
     } else { 
      wv.getSettings().setPluginState(PluginState.ON); 
     } 
     String venkat="<iframe src=\"http://player.vimeo.com/video/27244727?portrait=0&color=333\" width=\"WIDTH\" height=\"HEIGHT\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"; 
     wv.loadData(venkat,"text/html","UTF-8"); 
    } 
} 

Sau khi nghiên cứu từ google tôi đã viết mã trên nhưng không hoạt động. Trong này không có lỗi xảy ra nhưng khi tôi bấm vào thanh tiến trình chơi nút được hiển thị cho đôi khi và sau đó nó biến mất và hiển thị nút chơi một lần nữa ... Bất cứ ai có thể xin đề nghị tôi làm thế nào để giải quyết vấn đề này?cách phát video vimeo bằng iframe trong chế độ xem web?

Trả lời

-1
webView = (WebView)findViewById(R.id.presentation_webview); 

     webView.getSettings().setJavaScriptEnabled(true); 
     webView.getSettings().setAllowFileAccess(true); 
     webView.getSettings().setPluginsEnabled(true); 
     webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); 

     DisplayMetrics displaymetrics = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 
     int height = displaymetrics.heightPixels; 
     int wwidth = displaymetrics.widthPixels; 

     Log.e("h & w",wwidth+"-"+height); 

     String data_html = "<!DOCTYPE HTML> <html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:og=\"http://opengraphprotocol.org/schema/\" xmlns:fb=\"http://www.facebook.com/2008/fbml\"> <head></head> <body style=\"margin:0 0 0 0; padding:0 0 0 0;\"> <iframe width='"+wwidth+"' height='"+height+"' src=\"http://player.vimeo.com/video/"+VIDEO_ID+"\" frameborder=\"0\"></iframe> </body> </html> "; 

     webView.setWebViewClient(new MyWebViewClient()); 

     webView.loadDataWithBaseURL("http://vimeo.com", data_html, "text/html", "UTF-8", null); 

Hãy thử mã trên và sử dụng chiều rộng và chiều cao của thiết bị để phát video.

+0

tôi thử nghiệm nó trong motorola android 2.2.3 nhưng nó không làm việc – Venkat

1

Bạn phải bật tính năng tăng tốc phần cứng trong tệp kê khai andorid. Để làm việc vimeo video trên tất cả các thiết bị, bec vimeo video là loại html5 của video.

here is link of vimeo video play đang hoạt động hoàn hảo.

2

Làm điều này:

<iframe src="//player.vimeo.com/video/VIDEO_ID" 
     width="515" 
     height="340" 
     frameborder="0" 
     webkitallowfullscreen mozallowfullscreen allowfullscreen> 
</iframe> 
+1

làm thế nào để kích hoạt tính năng autoplay – Prasad

Các vấn đề liên quan