I am using YouTube API to play videos in my app. The video ID's are loaded from Firebase database.
This is the database structure:
This is the Adapter ViewHolder's code:
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
protected RelativeLayout relativeLayoutOverYouTubeThumbnailView;
TextView channel_name;
YouTubeThumbnailView youTubeThumbnailView;
public ImageView playButton;
public ViewHolder(@NonNull View itemView) {
super(itemView);
channel_name = itemView.findViewById(R.id.channel_name);
playButton = itemView.findViewById(R.id.btnYoutube_player);
playButton.setOnClickListener(this);
relativeLayoutOverYouTubeThumbnailView = itemView.findViewById(R.id.relativeLayout_over_youtube_thumbnail);
youTubeThumbnailView = itemView.findViewById(R.id.youtube_thumbnail);
}
@Override
public void onClick(View view) {
String id = list.get(getAdapterPosition()).getVid_ID();
// ERROR IN BELOW LINE
Intent intent = YouTubeStandalonePlayer.createVideoIntent((Activity) context, YoutubeConfig.getApiKey(), id, 100,
true,
false);
context.startActivity(intent);
This is my manifest:
<application
android:name=".FirebaseOffline"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".VideoActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name=".Video.VideoActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Whenever I click to play the video, this error occurs:
java.lang.ClassCastException: com.devapps.FirebaseOffline cannot be cast to android.app.Activity
.