I'm trying to include edmt.dev.videoplayer.VideoPlayerRecyclerView for showing multiple video in my android app. Builds without errors. But getting error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView. Can't detect what I'm doing wrong. Thanks in advance for helping.
Error Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gogon.wetest, PID: 15582
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class edmt.dev.videoplayer.VideoPlayerRecyclerView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.gogon.wetest.ui.watch.WatchFragment.onCreateView(WatchFragment.java:38)
fragment_watch.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/success_green"
tools:context="com.gogon.wetest.ui.watch.WatchFragment">
<edmt.dev.videoplayer.VideoPlayerRecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/video_player_id"
android:orientation="vertical"/>
</RelativeLayout>
WatchFragment.java
package com.gogon.wetest.ui.watch;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.gogon.wetest.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import butterknife.BindView;
import butterknife.ButterKnife;
import edmt.dev.videoplayer.VideoPlayerRecyclerView;
import edmt.dev.videoplayer.adapter.VideoPlayerRecyclerAdapter;
import edmt.dev.videoplayer.model.MediaObject;
import edmt.dev.videoplayer.utils.VerticalSpacingItemDecorator;
public class WatchFragment extends Fragment {
VideoPlayerRecyclerView videoPlayerRecyclerView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_watch, container, false);
videoPlayerRecyclerView = view.findViewById(R.id.video_player_id);
ButterKnife.bind(requireActivity());
init();
return view;
}
private void init() {
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
videoPlayerRecyclerView.setLayoutManager(layoutManager);
VerticalSpacingItemDecorator verticalSpacingItemDecorator = new VerticalSpacingItemDecorator(10);
videoPlayerRecyclerView.addItemDecoration(verticalSpacingItemDecorator);
ArrayList<MediaObject> sourceVideos = new ArrayList<>(sampleVideoList());
videoPlayerRecyclerView.setMediaObjects(sourceVideos);
VideoPlayerRecyclerAdapter videoAdapter = new VideoPlayerRecyclerAdapter(sourceVideos, initGlide());
videoPlayerRecyclerView.setAdapter(videoAdapter);
}
private RequestManager initGlide() {
RequestOptions requestOptions = new RequestOptions()
.placeholder(R.drawable.white_background)
.error(R.drawable.white_background);
return Glide.with(getContext()).setDefaultRequestOptions(requestOptions);
}
private List<MediaObject> sampleVideoList() {
return Arrays.asList(
//title, media-url, thumbnail, description
new MediaObject(
"For Bigger Blazes",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
"https://i.ytimg.com/vi/Dr9C2oswZfA/maxresdefault.jpg",
"Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
),
new MediaObject(
"Tears of Steel",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4",
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTSNuOK0PKeBYclnOvqAmKtUlJ_nQsN0YPYZ8gL7u-wKilHYs2S",
"Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
),
new MediaObject(
"What care can you get for a grand?",
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WhatCarCanYouGetForAGrand.mp4",
"https://www.jeep.com/content/dam/fca-brands/na/jeep/en_us/2021/grand-cherokee/gallery/exterior/MY21-Grand-Cherokee-Gallery-Exterior-Overland-Granite-Crystal-Desktop.jpg.image.1440.jpg",
"Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\\n\\nLicensed under the Creative Commons Attribution license\\nhttp://www.bigbuckbunny.org"
)
);
}
}
build.gradle:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'androidx.navigation.safeargs'
}
repositories {
google()
mavenCentral()
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.gogon.wetest"
minSdkVersion 21
targetSdkVersion 30
versionCode 5
versionName "1.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//enable view binding
buildFeatures {
viewBinding true
}
}
dependencies {
//for video player
implementation "com.google.android.exoplayer:exoplayer:2.16.1"
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
implementation 'com.github.eddydn:videoplayer:1.10'
//glide- for image loading and caching library
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
i found the reason, <edmt.dev.videoplayer.VideoPlayerRecyclerView> this is directory of VideoPlayerRecyclerView class in your project, edmt.dev.videoplayer prefix is package name of source code that you have copy it, replce whit your package directory,(directory of VideoPlayerRecyclerView class in your code)
for you is something like com.gogon.wetest.VideoPlayerRecyclerView , check the right directory address for VideoPlayerRecyclerView class