Created
July 6, 2020 09:09
-
-
Save oktavianto/4e6b79ab875ffead88c4f712f1f90fb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cn.jzvd.demo.Tab_3_List.ListView; | |
import android.os.Bundle; | |
import android.view.MenuItem; | |
import android.view.View; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.appcompat.app.AppCompatActivity; | |
import androidx.recyclerview.widget.LinearLayoutManager; | |
import androidx.recyclerview.widget.RecyclerView; | |
import cn.jzvd.Jzvd; | |
import cn.jzvd.demo.Tab_3_List.ListView.adapter.RecyclerViewAdapter; | |
import cn.jzvd.demo.R; | |
import cn.jzvd.demo.utils.AutoPlayUtils; | |
public class AutoPlayListViewActivity extends AppCompatActivity { | |
RecyclerView recyclerView; | |
RecyclerViewAdapter adapterVideoList; | |
private LinearLayoutManager mLayoutManager; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
getSupportActionBar().setDisplayShowHomeEnabled(true); | |
getSupportActionBar().setDisplayShowTitleEnabled(true); | |
getSupportActionBar().setDisplayUseLogoEnabled(false); | |
getSupportActionBar().setTitle(getString(R.string.list_auto_play)); | |
setContentView(R.layout.activity_recyclerview_content); | |
recyclerView = findViewById(R.id.recyclerview); | |
mLayoutManager = new LinearLayoutManager(this); | |
recyclerView.setLayoutManager(mLayoutManager); | |
adapterVideoList = new RecyclerViewAdapter(this); | |
recyclerView.setAdapter(adapterVideoList); | |
recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { | |
@Override | |
public void onChildViewAttachedToWindow(View view) { | |
} | |
@Override | |
public void onChildViewDetachedFromWindow(View view) { | |
Jzvd jzvd = view.findViewById(R.id.videoplayer); | |
if (jzvd != null && Jzvd.CURRENT_JZVD != null && | |
jzvd.jzDataSource.containsTheUrl(Jzvd.CURRENT_JZVD.jzDataSource.getCurrentUrl())) { | |
if (Jzvd.CURRENT_JZVD != null && Jzvd.CURRENT_JZVD.screen != Jzvd.SCREEN_FULLSCREEN) { | |
Jzvd.releaseAllVideos(); | |
} | |
} | |
} | |
}); | |
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | |
@Override | |
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { | |
super.onScrollStateChanged(recyclerView, newState); | |
if (newState == RecyclerView.SCROLL_STATE_IDLE) { | |
AutoPlayUtils.onScrollPlayVideo(recyclerView, R.id.videoplayer, mLayoutManager.findFirstVisibleItemPosition(), mLayoutManager.findLastVisibleItemPosition()); | |
} | |
} | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
if (dy != 0) { | |
AutoPlayUtils.onScrollReleaseAllVideos(mLayoutManager.findFirstVisibleItemPosition(), mLayoutManager.findLastVisibleItemPosition(), 0.2f); | |
} | |
} | |
}); | |
} | |
@Override | |
public void onBackPressed() { | |
if (Jzvd.backPress()) { | |
return; | |
} | |
super.onBackPressed(); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
Jzvd.releaseAllVideos(); | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case android.R.id.home: | |
finish(); | |
break; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment