Android Vimeo Video View Integration Example/Tutorial
MainActivity.java
MainActivity.java
package com.vimeoandroidintegration; import android.Manifest; import android.app.Activity; import android.graphics.Bitmap; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; public class MainActivity extends Activity { WebView webView; FrameLayout customViewContainer; myWebChromeClient mWebChromeClient; WebChromeClient.CustomViewCallback customViewCallback; myWebViewClient mWebViewClient; View mCustomView; String vimeolink ="http://player.vimeo.com/video/24577973"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); customViewContainer = (FrameLayout) findViewById(R.id.customViewContainer); webView = (WebView) findViewById(R.id.webView); mWebViewClient = new myWebViewClient(); webView.setWebViewClient(mWebViewClient); mWebChromeClient = new myWebChromeClient(); webView.setWebChromeClient(mWebChromeClient); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); settings.setMinimumFontSize(10); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); webView.setVerticalScrollBarEnabled(false); webView.loadUrl(vimeolink+"?player_id=player&autoplay=1&title=0&byline=0&portrait=0&api=1&maxheight=480&maxwidth=800"); } class myWebChromeClient extends WebChromeClient { private Bitmap mDefaultVideoPoster; private View mVideoProgressView; @Override public void onShowCustomView(View view, int requestedOrientation,CustomViewCallback callback) { onShowCustomView(view, callback); //To change body of overridden methods use File | Settings | File Templates. } @Override public void onShowCustomView(View view,CustomViewCallback callback) { // if a view already exists then immediately terminate the new one if (mCustomView != null) { callback.onCustomViewHidden(); return; } mCustomView = view; webView.setVisibility(View.GONE); customViewContainer.setVisibility(View.VISIBLE); customViewContainer.addView(view); customViewCallback = callback; } @Override public View getVideoLoadingProgressView() { if (mVideoProgressView == null) { LayoutInflater inflater = LayoutInflater.from(MainActivity.this); //mVideoProgressView = inflater.inflate(R.layout.video_progress, null); } return mVideoProgressView; } @Override
public void onHideCustomView() { super.onHideCustomView();
//To change body of overridden methods use File | Settings | File Templates.
if (mCustomView == null) return; webView.setVisibility(View.VISIBLE); customViewContainer.setVisibility(View.GONE); // Hide the custom view.
mCustomView.setVisibility(View.GONE); // Remove the custom view from its container.
customViewContainer.removeView(mCustomView); customViewCallback.onCustomViewHidden(); mCustomView = null; } } class myWebViewClient extends WebViewClient { @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { url =vimeolink; return super.shouldOverrideUrlLoading(view, url); } } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.vimeoandroidintegration.MainActivity"android:gravity="center"> <WebViewandroid:layout_width="match_parent"android:layout_height="fill_parent"android:id="@+id/webView"android:layout_gravity="center"android:background="#000000" /> <FrameLayoutandroid:id="@+id/customViewContainer"android:layout_width="match_parent"android:layout_height="fill_parent"android:visibility="visible" /> </RelativeLayout>
No comments:
Post a Comment