ARVI

Additional

Language
Java
Version
v1.2.0 (Sep 14, 2019)
Created
Nov 23, 2018
Updated
Sep 14, 2019
Owner
Arthur Ivanets (arthur3486)
Contributor
Arthur Ivanets (arthur3486)
1
Activity
Badge
Generate
Download
Source code
APK file

Promotion

ARVI - Autoplayable RecyclerView Items

ExoPlayer-based Android library that makes the implementation of the autoplayable RecyclerView video items an easy task

ARVI will enable you to make your feeds more interactive and appealing to your end users without the need to spend a lot of your valuable time on the implementation.

Contents

Demo (YouTube)

Getting Started

Prerequisites

1. Make sure that you've added the jcenter() repository to your top-level build.gradle file.

buildscript {
    //...
    repositories {
        //...
        jcenter()
    }
    //...
}

2. Enable the jetifier and androidX support in the top-level gradle.properties file.

//...
android.enableJetifier=true
android.useAndroidX=true
//....

3. Update your compileSdkVersion in the module-level build.gradle file to 28+.

//...
android {
    //...
    compileSdkVersion 28
    //...
}
//...

4. Replace your com.android.support.appcompat.* dependency with the new androidx.appcompat.* alternative.

//...
dependencies {
    //...
    implementation "androidx.appcompat:appcompat:1.0.1"
    //...
}
//...

5. Add the ExoPlayer dependency to the module-level build.gradle file.

//...
dependencies {
    //...
    implementation "com.google.android.exoplayer:exoplayer:2.9.2"
    //...
}
//...

ARVI Dependencies

ARVI is comprised of several library modules, namely:

  • arvi - core functionality (Required)
  • arvi-adapster - Adapster adaptation (Optional)
  • arvi-ktx - common extensions (Optional)
  • arvi-utils - common utils and helpers (Optional)

The basic implementation would have to include the core module

Latest version:

implementation "com.arthurivanets.arvi:arvi:X.Y.Z"

Which should be added to your module-level build.gradle file.

ext {
    //...
    arviLibraryVersion = "1.0.0"
}

dependencies {
    //...
    implementation "com.arthurivanets.arvi:arvi:$arviLibraryVersion"
}

After that you can proceed with further implementation.

See: Basic Implementation and Adapster-based Implementation

Basic Implementation

Basic implementation consists of 3 straightforward steps, which include the proper handling of the system memory claims, creation of the playable Item View Holder, and the incorporation of the Playable Items Container.

The steps you need to take:

1. Ensure the proper release of the active players when the application goes into background (System Memory Claims)

Kotlin (click to expand)

Basic

//...
import com.arthurivanets.arvi.PlayerProviderImpl

class ArviApplication : Application() {

    //...

    override fun onTrimMemory(level : Int) {
        super.onTrimMemory(level)

        if(level >= TRIM_MEMORY_BACKGROUND) {
            PlayerProviderImpl.getInstance(this).release()
        }
    }

    //...

}

With arvi-ktx

//...
import com.arthurivanets.arvi.ktx.playerProvider

class ArviApplication : Application() {

    //...

    override fun onTrimMemory(level : Int) {
        super.onTrimMemory(level)

        if(level >= TRIM_MEMORY_BACKGROUND) {
            playerProvider.release()
        }
    }

    //...

}

Java (click to expand)

//...importcom.arthurivanets.arvi.PlayerProviderImpl;

publicfinalclassYourApplicationextendsApplication {

    //...@OverridepublicvoidonTrimMemory(intlevel) {
        super.onTrimMemory(level);

        if(level >=TRIM_MEMORY_BACKGROUND) {
            PlayerProviderImpl.getInstance(this).release();
        }
    }
    
    //...

}



2. Implement your Item's ViewHolder based on the PlayableItemViewHolder

IMPORTANT: Your ViewHolder's layout.xml file must contain a

PlayerView child with an id @id/player_view.

See: BasicVideoItemViewHolder and item_video.xml

Kotlin (click to expand)

classBasicVideoItemViewHolder( parent :ViewGroup, itemView :View ) :PlayableItemViewHolder(parent, itemView) { //...overridefungetUrl() :String { return"video_url..." } //... }

Java (click to expand)

publicfinalclassBasicVideoItemViewHolderextendsPlayableItemViewHolder { //...@OverridepublicfinalStringgetUrl() { return"video_url..."; } //... }

3. Replace the regular RecyclerView with the PlayableItemsRecyclerView

IMPORTANT: PlayableItemsRecyclerView should be bound to the lifecycle of the Activity/Fragment (Activity/Fragment lifecycle events should be propagated to the

PlayableItemsRecyclerView) in order to ensure the correct handling of the item video playback.

See: PlayableItemsRecyclerView, BasicVideoItemsRecyclerViewAdapter, BasicVideosFragment and

fragment_videos.xmlKotlin (click to expand)

classBasicVideosFragment:BaseFragment() { //...overridefuninit(savedInstanceState :Bundle?) { with(recyclerView) { // PlayableItemRecyclerView configuration setPlaybackTriggeringStates( PlayableItemsContainer.PlaybackTriggeringState.IDLING, PlayableItemsContainer.PlaybackTriggeringState.DRAGGING ) autoplayMode =PlayableItemsContainer.AutoplayMode.ONE_AT_A_TIME adapter =BasicVideoItemsRecyclerViewAdapter( context = context!!, items =VideoProvider.getVideos(count =100, mute =true).toMutableList(), arviConfig =Config.Builder() .cache(ExoPlayerUtils.getCache(context!!)) .build() ) } } //...overridefunonResume() { super.onResume() recyclerView.onResume() } overridefunonPause() { super.onPause() recyclerView.onPause() } overridefunonDestroy() { recyclerView?.onDestroy() super.onDestroy() } //... }

Java (click to expand)