1

I am working on android app and users in my app can upload videos from youtube, vimeo or any other sources. Now I have a list of videos which I need to load in recyclerview. In recyclerview's list I have used

 <VideoView
    android:id="@+id/video_view"
    android:minHeight="1dp"
    android:visibility="gone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"/>

When I am loading videos from youtube or vimeo, it do not play these videos in videoview.

How can I play these videos in videoview and how can I give support to all type of videos to play in my android app.

Thank you much for all your help in advanced.

Prithniraj Nicyone
  • 5,021
  • 13
  • 52
  • 78

1 Answers1

1

You can find a full implementation here. But the general idea is that you'll need to use a WebView and you'll supply it with the embed data for a Vimeo video. You can also get the embed html for a video using the vimeo-networking-java SDK.

Here is the initial WebView setup:

mWebView = new WebView((Context) this);
mWebView.setLayoutParams(new LayoutParams(windowWidth, windowHeight));

mWebView.getSettings().setJavaScriptEnabled(true);
 // Watch the sdk level here, < 12 requires 'false
 // Wanted to force HTML5/264/mp4, you may want flash
 //    where still available
mWebView.getSettings().setPluginState(PluginState.OFF);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setUserAgentString("Android Mozilla/5.0 AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");

wcc = new MyWebChromeClient();
mWebView.setWebChromeClient(wcc);

wvc = new MyWebViewClient();
mWebView.setWebViewClient(wvc);
Community
  • 1
  • 1
Kyle Venn
  • 4,597
  • 27
  • 41
  • I cannot use webview as I have a list of videos and want to load that list in a recyclerview. Can you please suggest something else than webview which I can use to play any type of videos in android. Thanks a lot in advanced for all your help. – Prithniraj Nicyone Apr 28 '16 at 04:55
  • @PrithnirajNicyone having a list of VideoViews (all of which potentially playing at once), would be pretty bad for performance. Exoplayer is your best bet to support YouTube AND Vimeo vids - but that is also best as a single instance. I would suggest modifying your design to have a list of videos that a user clicks, which brings them to another Activity that can play a video. You can then use YouTube's embeddable player and Vimeo's WebView technique. As for getting both types of videos in a list, you could create a model object which has common fields across YT and Vim videos (name, desc, etc) – Kyle Venn Apr 28 '16 at 18:38