Skip to content

Commit

Permalink
Merge pull request #25 from rohan35/custom_views
Browse files Browse the repository at this point in the history
added support for custom play button image
  • Loading branch information
anirudhramanan committed May 3, 2020
2 parents deef5b4 + f470e55 commit 2121245
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

}
1 change: 1 addition & 0 deletions inline-youtube-view/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="progress_bar_dimensions">35dp</dimen>
<dimen name="play_icon_dimensions">48dp</dimen>
</resources>

0 comments on commit 2121245

Please sign in to comment.