I'm doing an application that lists youtube videos, I created a layout to inflate in the main activity and put the player in it
<com.google.android.youtube.player.YouTubePlayer
android:id="@+id/youtubeVideo"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/tvImageName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="172dp"
android:gravity="center"
android:text="Image name" />
But when I run, the error returns
android.view.InflateException: Binary XML file line #9: Binary XML
file line #9: Class is not a View
com.google.android.youtube.player.YouTubePlayer
Caused by: android.view.InflateException: Binary XML file line #9:
Class is not a View com.google.android.youtube.player.YouTubePlayer
Caused by: java.lang.ClassCastException: interface
com.google.android.youtube.player.YouTubePlayer cannot be cast to
android.view.View
Adapter:
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.VideoView;
import
com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.paivadeveloper.olheiros.Model.VideoUpload;
import com.paivadeveloper.olheiros.R;
import org.w3c.dom.Text;
import java.util.List;
public class VideoListAdapter extends ArrayAdapter<VideoUpload> {
private Activity context;
private int resource;
private List<VideoUpload> listImage;
private Boolean isPlaying = false;
private int current = 0;
private int duration = 0;
private ProgressBar currentProgress;
private VideoView img;
private TextView currentTime;
private YouTubePlayer youTubePlayerView;
YouTubePlayer.OnInitializedListener onInitializedListener;
public VideoListAdapter(@NonNull Activity context, @LayoutRes int
resource, @NonNull List<VideoUpload> objects) {
super(context, R.layout.image_item, objects);
this.context = context;
listImage = objects;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@SuppressLint("ViewHolder") View v =
inflater.inflate(R.layout.image_item, parent, false);
onInitializedListener = new YouTubePlayer.OnInitializedListener()
{
@Override
public void onInitializationSuccess(YouTubePlayer.Provider
provider, YouTubePlayer youTubePlayer, boolean b) {
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider
provider, YouTubeInitializationResult
youTubeInitializationResult) {
}
};
TextView tvName = v.findViewById(R.id.tvImageName);
YouTubePlayerView youTubePlayerView =
(YouTubePlayerView)v.findViewById(R.id.youtube_player);
String tvNameString;
tvNameString = listImage.get(position).getName();
tvName.setText(tvNameString);
return v;
}
}