【发布时间】:2022-02-04 18:44:45
【问题描述】:
我正在尝试包含 edmt.dev.videoplayer.VideoPlayerRecyclerView 以在我的 Android 应用中显示多个视频。构建没有错误。但是膨胀类 edmt.dev.videoplayer.VideoPlayerRecyclerView 时出错。无法检测到我做错了什么。提前感谢您的帮助。
错误日志:
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'
}
【问题讨论】:
标签: java android android-recyclerview android-videoview