diff --git a/app/src/main/java/com/flipkart/youtubeviewdemo/youtubenative/YouTubePlayerAdapter.java b/app/src/main/java/com/flipkart/youtubeviewdemo/youtubenative/YouTubePlayerAdapter.java index 3c8031e..20993d9 100644 --- a/app/src/main/java/com/flipkart/youtubeviewdemo/youtubenative/YouTubePlayerAdapter.java +++ b/app/src/main/java/com/flipkart/youtubeviewdemo/youtubenative/YouTubePlayerAdapter.java @@ -18,14 +18,15 @@ */ package com.flipkart.youtubeviewdemo.youtubenative; -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; + import com.flipkart.youtubeview.YouTubePlayerView; import com.flipkart.youtubeview.models.ImageLoader; import com.flipkart.youtubeviewdemo.R; @@ -76,6 +77,13 @@ public void onBindViewHolder(@NonNull final YouTubePlayerViewHolder holder, int String videoId = videoIds.get(position); playerView.initPlayer(Constants.API_KEY, videoId, "https://cdn.rawgit.com/flipkart-incubator/inline-youtube-view/60bae1a1/youtube-android/youtube_iframe_player.html", playerType, null, fragment, imageLoader); + /*if you want to have your custom icon instead of default icon. Use the below code + and add your own image as below. Make sure to call below method after initPlayer + */ + //playerView.overridePlayIcon("https://i.ibb.co/ZKZ2qdc/ic-launcher.png"); + + //if you have the resource id then pass it as below + //playerView.overridePlayIcon(R.mipmap.ic_launcher); } static class YouTubePlayerViewHolder extends RecyclerView.ViewHolder { diff --git a/inline-youtube-view/src/main/java/com/flipkart/youtubeview/YouTubePlayerView.java b/inline-youtube-view/src/main/java/com/flipkart/youtubeview/YouTubePlayerView.java index 01ddb9c..1ba3a4f 100644 --- a/inline-youtube-view/src/main/java/com/flipkart/youtubeview/YouTubePlayerView.java +++ b/inline-youtube-view/src/main/java/com/flipkart/youtubeview/YouTubePlayerView.java @@ -21,11 +21,6 @@ import android.content.Context; import android.graphics.PorterDuff; import android.os.Build; -import androidx.annotation.MainThread; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; import android.text.TextUtils; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -36,6 +31,13 @@ import android.widget.ImageView; import android.widget.ProgressBar; +import androidx.annotation.DrawableRes; +import androidx.annotation.MainThread; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + import com.flipkart.youtubeview.fragment.YouTubeBaseFragment; import com.flipkart.youtubeview.fragment.YouTubeFragment; import com.flipkart.youtubeview.fragment.YouTubeWebViewFragment; @@ -127,7 +129,6 @@ private void init(@NonNull Context context) { playerContainer.setId(0); thumbnailImageView = itemView.findViewById(R.id.video_thumbnail_image); playIcon = itemView.findViewById(R.id.play_btn); - ProgressBar progressBar = itemView.findViewById(R.id.recycler_progressbar); // For else case there is a layout defined for v21 and above if (progressBar != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { @@ -233,4 +234,32 @@ protected void onDetachedFromWindow() { unbindPlayer(); super.onDetachedFromWindow(); } + + /** + * this function helps to configure the play icon image + * + * @param resId the resource identifier of the drawable + **/ + public void overridePlayIcon(@DrawableRes int src) { + if (playIcon != null) { + playIcon.setImageResource(src); + } + } + + /** + * this function helps to configure the play icon image + * + * @param imageUrl the resource identifier of the drawable + **/ + public void overridePlayIcon(@NonNull String url) { + $Precondition$Check.checkArgument(!TextUtils.isEmpty(url), "Image Url cannot be null"); + $Precondition$Check.checkArgument(!(imageLoader == null), + "Image loader cannot be null. Make sure you have called initPlayer method"); + // override play icon + if (playIcon != null) { + int playIconDimen = (int) getContext().getResources().getDimension(R.dimen.play_icon_dimensions); + imageLoader.loadImage(playIcon, url, playIconDimen, playIconDimen); + } + } + } diff --git a/inline-youtube-view/src/main/res/values/dimens.xml b/inline-youtube-view/src/main/res/values/dimens.xml index 33222ab..e5a82f3 100644 --- a/inline-youtube-view/src/main/res/values/dimens.xml +++ b/inline-youtube-view/src/main/res/values/dimens.xml @@ -1,4 +1,5 @@ 35dp + 48dp