toro icon indicating copy to clipboard operation
toro copied to clipboard

Need To play single Video and Multiple GIF

Open charlizesmith opened this issue 5 years ago • 6 comments

Hello Nam,

I am using Toro version : latest_release = '3.6.2.2804'

In Recycleview, Autoplay and Autopause with Gif and Video is working fine. I am using LinearLayout manager with Toro Container and its working awesome.

Now, I want to use Staggeredgridlayoutmanager with ToroContainer for loading 1 video and 4 gif in screen. As per your documentaion in advance Topic, ** Playing multiple Videos at once is considered bad practice. **

video and gif are both with .mp4 extension. So i want to load gif with ToroPlayer. I studied your complex grid example and loaded 1 video and 4 gif successfully. According to this, it create dynamic number of player.

NOW My FIRST QUESTION IS : once I scrolled items in recycle-view, scrolled item player will be removed dynamically or i have to manage and clear the player list?

SECOND QUESTION IS: Is it will cause any memory issue or not?

I used config = new Config.Builder().setMediaSourceBuilder(MediaSourceBuilder.LOOPING) for playing Gif in loop.

THIRD QUESTION IS: I am not getting meaning of this below line. Why you mention "// A demo of using PlayerDispatcher flexible, may not be practical.//" comment.

toroContainer.setPlayerDispatcher(player -> player.getPlayerOrder() % 2 == 1 ? 0 : 1500);

MY CODE IS

 // Custom player selector for a complicated playback in grid
        activeSelector = new PlayerSelector() {
            @NonNull
            @Override public Collection<ToroPlayer> select(@NonNull Container container,
                                                           @Sorted(order = Sorted.Order.ASCENDING) @NonNull List<ToroPlayer> items) {
                List<ToroPlayer> toSelect;
                int count = items.size();
                if (count < 1) {
                    toSelect = Collections.emptyList();
                } else {
                    int firstOrder = items.get(0).getPlayerOrder();
//                    int span = layoutManager.getSpanSizeLookup().getSpanSize(firstOrder);
//                    count = Math.min(count, layoutManager.getSpanCount() / span);
                    count = items.size();
                    toSelect = new ArrayList<>();
                    for (int i = 0; i < count; i++) {
                        toSelect.add(items.get(i));
                    }
                }

                return toSelect;
            }

            @NonNull @Override public PlayerSelector reverse() {
                return this;
            }
        };
    // A demo of using PlayerDispatcher flexible, may not be practical.
        toroContainer.setPlayerDispatcher(player -> player.getPlayerOrder() % 2 == 1 ? 0 : 1500);
        toroCntainer.setPlayerSelector(activeSelector)

==============================================================

charlizesmith avatar Jul 26 '19 10:07 charlizesmith

@charlizesmith sorry for late reply, please find my answers below

(1) Once ViewHolder is detached, the player resource is cleared automatically. (2) As a result, there should be no memory leaked or so. But if you find them please file issue. (3) It is just to show you how you can set PlayerDispatcher for dynamic delay. What I mean is we may never see dynamic delay playback (i.e each player starts with different delay) in practice. Because It looks weird I suppose. But it is no harm so you are free to do so.

eneim avatar Aug 07 '19 04:08 eneim

@eneim Thanks a lot eneim for your reply. NOW The ISSUE IS

  • Whenever i try to load multiple gif and video, app became little slow. I am loading video and gif with streaming url. Is it the issue because of loading video and gif at the same time or some other thing?

sanketmthakare avatar Aug 07 '19 09:08 sanketmthakare

@sanketmthakare as said, playing multiple items at a time is power consuming. To ensure, you can configure it to play only one or no items and see how it changes.

eneim avatar Aug 07 '19 11:08 eneim

@eneim Thanks eneim. above, you said playing multiple items at a time is power consuming. But, I want to use Staggeredgridlayoutmanager with ToroContainer.

How can i play single video with Staggeredgridlayout? Is there any optimize solution to avoid power consuming while playing multiple video?

In your complicated grid sample , you are playing both video at a time.

charlizesmith avatar Aug 07 '19 11:08 charlizesmith

@charlizesmith I think by default Toro will play only one at a time, regardless of which LayoutManager you use. You just don't need to provide any PlayerSelector.

My sample is to demonstrate the capability, but not the recommended practice.

The performance depends on your device, and the video spec as well. So make sure to also check the video's information.

eneim avatar Aug 07 '19 12:08 eneim

@eneim ok will check it. Thanks for reply

charlizesmith avatar Aug 07 '19 13:08 charlizesmith