// Create new views (invoked by the layout manager) public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { try { View itemView; if (viewType == (int)NativeFeedType.Video) { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_VideoFeed, parent, false); Holders.VideoAdapterViewHolder vh = new Holders.VideoAdapterViewHolder(itemView, OnClick, OnLongClick); return(vh); } else if (viewType == (int)NativeFeedType.Youtube) { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_YoutubeFeed, parent, false); Holders.YoutubeAdapterViewHolder vh = new Holders.YoutubeAdapterViewHolder(itemView, OnClick, OnLongClick); return(vh); } else if (viewType == (int)NativeFeedType.Gif || viewType == (int)NativeFeedType.Photo) { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_PhotoFeed, parent, false); Holders.PhotoAdapterViewHolder vh = new Holders.PhotoAdapterViewHolder(itemView, OnClick, OnLongClick); return(vh); } else if (viewType == (int)NativeFeedType.Funding) { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.ViewModel_HRecyclerView, parent, false); Holders.FundingViewHolder vh = new Holders.FundingViewHolder(ActivityContext, itemView); return(vh); } else if (viewType == (int)NativeFeedType.AdMob) { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.PostType_AdMob, parent, false); Holders.AdMobAdapterViewHolder vh = new Holders.AdMobAdapterViewHolder(itemView); return(vh); } else { itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Style_MultiPhotoFeed, parent, false); Holders.MultiPhotoAdapterViewHolder vh = new Holders.MultiPhotoAdapterViewHolder(itemView, OnClick, OnLongClick); return(vh); } } catch (Exception exception) { Console.WriteLine(exception); return(null); } }
public ExoPlayerRecyclerEvent(PlayerControlView controlView, PRecyclerView recyclerView, Holders.VideoAdapterViewHolder holder) { XRecyclerView = recyclerView; if (controlView == null) { return; } mFullScreenIcon = controlView.FindViewById <ImageView>(Resource.Id.exo_fullscreen_icon); mFullScreenButton = controlView.FindViewById <FrameLayout>(Resource.Id.exo_fullscreen_button); VideoPlayButton = controlView.FindViewById <ImageButton>(Resource.Id.exo_play); VideoResumeButton = controlView.FindViewById <ImageButton>(Resource.Id.exo_pause); VolumeControl = controlView.FindViewById <ImageView>(Resource.Id.exo_volume_icon); if (!AppSettings.ShowFullScreenVideoPost) { mFullScreenIcon.Visibility = ViewStates.Gone; mFullScreenButton.Visibility = ViewStates.Gone; } if (holder.VideoProgressBar != null) { LoadingProgressBar = holder.VideoProgressBar; } SetVolumeControl(XRecyclerView.VolumeStateProvider == VolumeState.On? VolumeState.On: VolumeState.Off); if (!VolumeControl.HasOnClickListeners) { VolumeControl.Click += (sender, args) => { ToggleVolume(); }; } }
public void PlayVideo(bool isEndOfList, Holders.VideoAdapterViewHolder holderVideoPlayer = null, PostsObject item = null) { try { if (VideoPlayer == null) { SetPlayer(); } int targetPosition; if (!isEndOfList) { var startPosition = ((LinearLayoutManager)GetLayoutManager()).FindFirstVisibleItemPosition(); var endPosition = ((LinearLayoutManager)GetLayoutManager()).FindLastVisibleItemPosition(); if (endPosition - startPosition > 1) { endPosition = startPosition + 1; } if (startPosition < 0 || endPosition < 0) { return; } if (startPosition != endPosition) { var startPositionVideoHeight = GetVisibleVideoSurfaceHeight(startPosition); var endPositionVideoHeight = GetVisibleVideoSurfaceHeight(endPosition); targetPosition = startPositionVideoHeight > endPositionVideoHeight ? startPosition : endPosition; } else { targetPosition = startPosition; } } else { targetPosition = GetAdapter().ItemCount - 1; } if (targetPosition == PlayPosition) { return; } // set the position of the list-item that is to be played PlayPosition = targetPosition; if (VideoSurfaceView == null) { return; } VideoSurfaceView.Visibility = ViewStates.Invisible; RemoveVideoView(VideoSurfaceView); var currentPosition = targetPosition - ((LinearLayoutManager)GetLayoutManager()).FindFirstVisibleItemPosition(); var child = GetChildAt(currentPosition); if (child == null) { return; } dynamic holder; if (holderVideoPlayer != null) { holder = holderVideoPlayer; targetPosition = holderVideoPlayer.LayoutPosition; } else { Holders.VideoAdapterViewHolder holderChild = (Holders.VideoAdapterViewHolder)child.Tag; if (holderChild == null) { PlayPosition = -1; return; } else { targetPosition = holderChild.LayoutPosition; holder = holderChild; } } if (!(holder is Holders.VideoAdapterViewHolder holderVideo)) { return; } MediaContainerLayout = holderVideo.MediaContainerLayout; Thumbnail = holderVideo.VideoImage; ViewHolderParent = holderVideo.ItemView; PlayControl = holderVideo.PlayControl; if (!IsVideoViewAdded) { AddVideoView(); } holderVideo.VideoProgressBar.Visibility = ViewStates.Visible; VideoSurfaceView.Player = VideoPlayer; var controlView = VideoSurfaceView.FindViewById <PlayerControlView>(Resource.Id.exo_controller); Uri videoUrl = Uri.Parse(item != null ? item.MediaSet[0].File : NativeFeedAdapter.PixelNewsFeedList[targetPosition].MediaSet[0].File); //>> Old Code //===================== Exo Player ======================== var lis = new ExoPlayerRecyclerEvent(controlView, this, holderVideo); IMediaSource videoSource = GetMediaSourceFromUrl(videoUrl, "normal"); var dataSpec = new DataSpec(videoUrl); //0, 1000 * 1024, null if (Cache == null) { CacheVideosFiles(videoUrl); } //Cache = new SimpleCache(new Java.IO.File(MainContext.FilesDir, "media"), new NoOpCacheEvictor()); if (CacheDataSourceFactory == null) { CacheDataSourceFactory = new CacheDataSourceFactory(Cache, DefaultDataSourceFac); } var counters = new CacheUtil.CachingCounters(); CacheUtil.GetCached(dataSpec, Cache, counters); if (counters.ContentLength == counters.TotalCachedBytes()) { videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl); } else if (counters.TotalCachedBytes() == 0) { videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl); // not cached at all Task.Run(() => { try { var cacheDataSource = new CacheDataSource(Cache, CacheDataSourceFactory.CreateDataSource()); CacheUtil.Cache(dataSpec, Cache, cacheDataSource, counters, new AtomicBoolean()); double downloadPercentage = counters.TotalCachedBytes() * 100d / counters.ContentLength; Console.WriteLine(downloadPercentage); } catch (Exception e) { Console.WriteLine(e); } }); } else { // partially cached videoSource = new ExtractorMediaSource.Factory(CacheDataSourceFactory).CreateMediaSource(videoUrl); } lis.mFullScreenButton.SetOnClickListener(new NewClicker(lis.mFullScreenButton, videoUrl.ToString(), this)); VideoPlayer.Prepare(videoSource); VideoPlayer.AddListener(lis); VideoPlayer.PlayWhenReady = true; } catch (Exception e) { Console.WriteLine(e); } }