Open tranquoctrungcntt opened 5 years ago
Also experiencing this issue.. were you able to fix this issue @tranquoctrungcntt ?
not yet, hope @eneim helps us
@tranquoctrungcntt @jaytarub Can you guys explain more about this issue? When it happens (scroll slowly or fast scrolling, Android version? Device model, library version?).
@eneim I used the lasted version of library, and when I scroll ( just scroll, even slow or fast ) , my app will crash . thanks for helping @eneim
@tranquoctrungcntt Can you send me the code of your ViewHolder that implement ToroPlayer? It will be even better if you can extract your code to a small project that can still reproduce the issue.
sorry but now i am doing a new approach. i will do it again as soon as posible
@tranquoctrungcntt Thanks and sorry for the inconvenience.
btw, i have 2 difference layouts to inflat and i did exactly what you wrote in README.
@eneim Am getting thesame error today
Below is my code
`public class ListAdapter extends RecyclerView.Adapter { @Nullable ExoPlayerViewHelper helper;
Uri mediaUri;
Context context;
ArrayList<Item> item = new ArrayList<>();
public ListAdapter(ArrayList<Item> item) {
this.item = item;
}
@Override
public int getItemViewType(int position) {
if (item.get(position).getType().equalsIgnoreCase("image")) {
return 0;
} else {
return 1;
}
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view;
if (viewType == 0) {
view = inflater.inflate(R.layout.list_two, parent, false);
return new listOneVM(view);
}
view = inflater.inflate(R.layout.list_one, parent, false);
return new listTwoVM(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (item.get(position).getType().equalsIgnoreCase("image")) {
//set the view holder for ads with video
listOneVM listOneVM = (listOneVM) holder;
listOneVM.textView.setText(item.get(position).getName());
listOneVM.bind(Uri.parse(item.get(position).getUrl()));
} else {
listTwoVM listTwoVM = (listTwoVM) holder;
listTwoVM.textView.setText(item.get(position).getName());
listTwoVM.textView2.setText(item.get(position).getAge());
}
}
@Override
public int getItemCount() {
return item.size();
}
class listOneVM extends RecyclerView.ViewHolder implements ToroPlayer {
TextView textView;
PlayerView playerView;
public listOneVM(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.name);
playerView = itemView.findViewById(R.id.video_player);
}
// called from Adapter to setup the media
void bind(Uri item) {
if (item != null) {
mediaUri = item;
}
}
@NonNull
@Override
public View getPlayerView() {
return playerView;
}
@NonNull
@Override
public PlaybackInfo getCurrentPlaybackInfo() {
return helper != null ? helper.getLatestPlaybackInfo() : new PlaybackInfo();
}
@Override
public void initialize(@NonNull Container container, @NonNull PlaybackInfo playbackInfo) {
if (helper == null) {
helper = new ExoPlayerViewHelper(this, mediaUri);
helper.addPlayerEventListener(toroPlayerEventListener);
}
helper.initialize(container, playbackInfo);
}
private ToroPlayer.EventListener toroPlayerEventListener = new EventListener() {
@Override
public void onFirstFrameRendered() {
}
@Override
public void onBuffering() {
}
@Override
public void onPlaying() {
}
@Override
public void onPaused() {
}
@Override
public void onCompleted() {
}
};
@Override
public void play() {
if (helper != null) helper.play();
}
@Override
public void pause() {
if (helper != null) helper.pause();
}
@Override
public boolean isPlaying() {
boolean isPlaying = false;
try {
isPlaying = helper != null && helper.isPlaying();
} catch (Exception e) {
e.printStackTrace();
}
return isPlaying;
}
@Override
public void release() {
if (helper != null) {
helper.release();
helper = null;
}
}
@Override
public boolean wantsToPlay() {
try {
return ToroUtil.visibleAreaOffset(this, itemView.getParent()) >= 0.50;
} catch (Exception e) {
e.printStackTrace();
release();
return false;
}
}
@Override
public int getPlayerOrder() {
return getAdapterPosition();
}
}
`
Here is the error
Process: com.example.torotest, PID: 21028 java.lang.IllegalStateException: Player is playing while it is not in managed state: listOneVM{e23054a position=1 id=-1, oldPos=-1, pLpos:-1} at im.ene.toro.widget.Container.onChildDetachedFromWindow(Container.java:259) at androidx.recyclerview.widget.RecyclerView.dispatchChildDetached(RecyclerView.java:7539) at androidx.recyclerview.widget.RecyclerView$5.removeViewAt(RecyclerView.java:872) at androidx.recyclerview.widget.ChildHelper.removeViewAt(ChildHelper.java:168) at androidx.recyclerview.widget.RecyclerView$LayoutManager.removeViewAt(RecyclerView.java:8639) at androidx.recyclerview.widget.RecyclerView$LayoutManager.removeAndRecycleViewAt(RecyclerView.java:8912) at androidx.recyclerview.widget.LinearLayoutManager.recycleChildren(LinearLayoutManager.java:1429) at androidx.recyclerview.widget.LinearLayoutManager.recycleViewsFromStart(LinearLayoutManager.java:1479) at androidx.recyclerview.widget.LinearLayoutManager.recycleByLayoutState(LinearLayoutManager.java:1554) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1578) at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1391) at androidx.recyclerview.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1128) at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1841) at androidx.recyclerview.widget.RecyclerView.scrollByInternal(RecyclerView.java:1940) at androidx.recyclerview.widget.RecyclerView.onTouchEvent(RecyclerView.java:3391) at android.view.View.dispatchTouchEvent(View.java:12527) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3026) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2705) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3032) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719) at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:444) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1835) at android.app.Activity.dispatchTouchEvent(Activity.java:3465) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:402) at android.view.View.dispatchPointerEvent(View.java:12768) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5287) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5087) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4602) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4655) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4621) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4761) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4629) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4818) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4602) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4655) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4621) 2020-07-19 21:23:49.763 21028-21028/com.example.torotest E/AndroidRuntime: at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4629) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4602) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7330) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7299) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7260) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7436) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:247) at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:212) at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7404) at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7459) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092) at android.view.Choreographer.doCallbacks(Choreographer.java:888) at android.view.Choreographer.doFrame(Choreographer.java:813) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6810) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
i am using recyclerview, when i scroll list , this thing happen