All Projects → mobileappsvn → AutoPlayVideoRecyclerView

mobileappsvn / AutoPlayVideoRecyclerView

Licence: Apache-2.0 license
Android library to auto play video from url in Recyclerview.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to AutoPlayVideoRecyclerView

ARVI
Android library designed to simplify the implementation of the video autoplay in the RecyclerView
Stars: ✭ 69 (+56.82%)
Mutual labels:  recyclerview, autoplay
ConcatAdapter-sample
Load more recyclerview android using ConcatAdapter | Sample to practice RecyclerView ConcatAdapter
Stars: ✭ 26 (-40.91%)
Mutual labels:  recyclerview
Mjolnirrecyclerview
[DEPRECATED] This library is no longer maintained and it will not receive any more updates.
Stars: ✭ 233 (+429.55%)
Mutual labels:  recyclerview
Linkage Recyclerview
即使不用饿了么订餐,也请务必收藏好该库!🔥 一行代码即可接入,二级联动订餐列表。
Stars: ✭ 2,970 (+6650%)
Mutual labels:  recyclerview
Pageindicator
An Instagram like page indicator compatible with RecyclerView and ViewPager.
Stars: ✭ 236 (+436.36%)
Mutual labels:  recyclerview
Nytimes App
🗽 A Simple Demonstration of the New York Times App 📱 using Jsoup web crawler with MVVM Architecture 🔥
Stars: ✭ 246 (+459.09%)
Mutual labels:  recyclerview
Overscroll Decor
Android: iOS-like over-scrolling effect applicable over almost all scrollable Android views.
Stars: ✭ 2,671 (+5970.45%)
Mutual labels:  recyclerview
XTableView
一个基于RecyclerView+Scroller实现的二维表格组件,同时支持侧滑菜单、拖动调整列表顺序等拓展功能。A two-dimensional table view, base on recyclerview, both support to side slide menu、drag item and more.
Stars: ✭ 15 (-65.91%)
Mutual labels:  recyclerview
InstantRecyclerView
A library that helps to implement a complex list with RecyclerView.(RecyclerView使用的封装与优化,帮助你快速利用RecyclerView构建复杂列表)
Stars: ✭ 22 (-50%)
Mutual labels:  recyclerview
Snaphelperexample
SnapHelper Example for Android Application
Stars: ✭ 245 (+456.82%)
Mutual labels:  recyclerview
Adapterdelegates
"Favor composition over inheritance" for RecyclerView Adapters
Stars: ✭ 2,735 (+6115.91%)
Mutual labels:  recyclerview
Shswiperefreshlayout
Android 升级版 SwipeRefreshLayout,支持RecyclerView、ScrollView等大部分组件,下拉刷新(Refresh)和上拉加载(Loadmore),支持自定义HeaderView和FooterView
Stars: ✭ 236 (+436.36%)
Mutual labels:  recyclerview
android-file-manager
A File Manager for Android
Stars: ✭ 19 (-56.82%)
Mutual labels:  recyclerview
Recyclerviewhelper
RecyclerView功能拓展
Stars: ✭ 235 (+434.09%)
Mutual labels:  recyclerview
recyclerview-adapters
Multiple item adapters for RecyclerView (inspired by Merge Adapter)
Stars: ✭ 24 (-45.45%)
Mutual labels:  recyclerview
Dsladapter
🔥 Kotlin时代的Adapter, Dsl 的形式使用 RecyclerView.Adapter, 支持折叠展开, 树结构,悬停,情感图状态切换, 加载更多, 多类型Item,侧滑菜单等
Stars: ✭ 231 (+425%)
Mutual labels:  recyclerview
Pagerecyclerview
PageRecyclerView achieves page turning function and unlimited carousel
Stars: ✭ 241 (+447.73%)
Mutual labels:  recyclerview
Lazyrecycleradapter
极简通用的RecyclerAdapter,入侵性低,支持一个列表多种Item类型,无需维护和编写Adapter代码,快速集成拥有点击,动画,自定义刷新,自定义加载更多,自定义空页面显示,通用分割线,动态绑定等高复用,你只需要编写维护Holder代码。
Stars: ✭ 251 (+470.45%)
Mutual labels:  recyclerview
Vitrin
A simple app that shows categories, subcategories and items.
Stars: ✭ 70 (+59.09%)
Mutual labels:  recyclerview
recyclerview-selection-demo
A simple Android project that demonstrates the usage of the androidx.recyclerview.selection support library
Stars: ✭ 27 (-38.64%)
Mutual labels:  recyclerview

AutoplayVideo

This library is created with the purpose to implement recyclerview with videos easily.

It is targeted at solving following problems:

  1. Flicker when scrolling.
  2. Lag or skipping frames when video starts.
  3. OutOfMemory errors.

And it has following features:

  1. Auto-play videos when in view.
  2. Auto-pause videos when not in view or partially in view.
  3. Mute/Un-mute videos.
  4. Option to play only first visible video.
  5. Download videos to local storage in background for faster loading.

Demo [Click to image to view on Youtube link]

Watch the video

Download

Gradle

Step 1. Add the jCenter repository to your project-level build.gradle file

allprojects {
	repositories {
		jcenter()
	}
}

Step 2. Add the dependency to your app-level build.gradle file:

dependencies {
	 compile 'com.robert.autoplayvideo:0.1.2'
}

Or Maven

<dependency>
  <groupId>com.robert</groupId>
  <artifactId>autoplayvideo</artifactId>
  <version>0.1.2</version>
  <type>pom</type>
</dependency>

Usage

Add VideoImage to your xml file for single list item single_card.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
       
       <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

             <FrameLayout
                android:layout_width="300dp"
                android:layout_height="150dp">

                <com.robert.autoplayvideo.VideoImage
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

                <ImageView
                    android:id="@+id/img_vol"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right|bottom"
                    android:layout_margin="8dp"
                    android:src="@drawable/ic_unmute"/>
            </FrameLayout>

            <TextView
                android:id="@+id/tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center" />
		
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

Add CustomRecyclerView to your Activity layout xml MainActivity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.robert.autoplayvideo.CustomRecyclerView
        android:id="@+id/rv_home"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
	
</LinearLayout>

Set Adapter with following specifics:

  1. Adapter should extend VideosAdapter.
  2. ViewHolder should extend CustomViewHolder.
  3. Set thumbnail image url and video url in onBindViewHolder method.
public class MyVideosAdapter extends VideosAdapter {

    private List<MyModel> list;
    Picasso picasso;

    public class MyViewHolder extends CustomViewHolder {
        final TextView tv;
	final ImageView img_vol,img_playback;
        boolean isMuted; //to mute/un-mute video (optional)
	
        public MyViewHolder(View x) {
            super(x);
            tv = ButterKnife.findById(x, R.id.tv);
	    img_vol = ButterKnife.findById(x, R.id.img_vol);
	    img_playback = ButterKnife.findById(x, R.id.img_playback);
        }
    }

    public MyVideosAdapter(List<MyModel> list_urls, Picasso p) {
        this.list = list_urls;
        this.picasso = p;
    }

    @Override
    public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.single_card, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(CustomViewHolder holder, int position) {
        ((MyViewHolder) holder).tv.setText(list.get(position).getName());

        //todo
        holder.setImageUrl(list.get(position).getImage_url());
        holder.setVideoUrl(list.get(position).getVideo_url());
        //load image/thumbnail into imageview
        if (list.get(position).getImage_url() != null && !list.get(position).getImage_url().isEmpty())
            picasso.load(holder.getImageUrl()).config(Bitmap.Config.RGB_565).into(holder.getImageView());
    }
    
    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 0;
    }
}

Finally setActivity in your Activity before setting the adapter and (Optional) scroll programmatically to initiate videos on initial screen:

    recyclerView.setActivity(this); //todo before setAdapter
    recyclerView.setAdapter(mAdapter);

Play only 1st video (Optional)

Setting this parameter will play video only in 1st completely visible RecyclerView ViewHolder.

recyclerView.setPlayOnlyFirstVideo(true); // false by default

Download videos to local storage (Optional)

You can start downloading video in background on viewholder loaded. You can change download path.

recyclerView.setDownloadPath(Environment.getExternalStorageDirectory() + "/MyVideo"); //optional
recyclerView.setDownloadVideos(true); // false by default

Optionally you can start pre-downloading all the videos by passing list of URLs to function as below:

List<String> urls = new ArrayList<>();
 for (MyModel object : modelList) {
     if (object.getVideo_url() != null && object.getVideo_url().endsWith(".mp4"))
         urls.add(object.getVideo_url());
 }
recyclerView.preDownload(urls);

Note: Do not forget to add WRITE_EXTERNAL_STORAGE permission in the Manifest file and also ask for runtime permission in devices above Marshmallow.

Remove check for .mp4 (Optional)

By default it checks for url to end with .mp4 else it is not considered as video URL. You can override this by setting parameter as below. Please use this with caution and make sure you provide video URL only.

recyclerView.setCheckForMp4(false); // true by default

Get callbacks when videos starts and pauses

You can override the below methods of CustomViewHolder to get callback when video starts to play or pauses.

	@Override
        public void videoStarted() {
            super.videoStarted();
            img_playback.setImageResource(R.drawable.ic_pause);
            if (isMuted) {
                muteVideo();
                img_vol.setImageResource(R.drawable.ic_mute);
            } else {
                unmuteVideo();
                img_vol.setImageResource(R.drawable.ic_unmute);
            }
        }
        @Override
        public void pauseVideo() {
            super.pauseVideo();
            img_playback.setImageResource(R.drawable.ic_play);
        }

Play or pause videos manually

You can allow the user to play or pause any video by adding below code in onBindViewHolder:

	((MyViewHolder) holder).img_playback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (holder.isPlaying()) {
                    holder.pauseVideo();
                    holder.setPaused(true);
                } else {
                    holder.playVideo();
                    holder.setPaused(false);
                }
            }
        });

Mute or Unmute the videos

Video can be muted/unmuted by adding below code in onBindViewHolder:

	holder.getAah_vi().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (((MyViewHolder) holder).isMuted) {
                    holder.unmuteVideo();
                    ((MyViewHolder) holder).img_vol.setImageResource(R.drawable.ic_unmute);
                } else {
                    holder.muteVideo();
                    ((MyViewHolder) holder).img_vol.setImageResource(R.drawable.ic_mute);
                }
                ((MyViewHolder) holder).isMuted = !((MyViewHolder) holder).isMuted;
            }
        });

Set looping on videos

Set looping on videos by adding below code in onBindViewHolder:

holder.setLooping(true); //optional - true by default

Changelog

License

Copyright 2017 Robert Hoang

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].