我在播放视频时遇到问题,它无法正常工作
Posted
技术标签:
【中文标题】我在播放视频时遇到问题,它无法正常工作【英文标题】:I have problem when i play video it's not working 【发布时间】:2021-11-18 03:19:33 【问题描述】:无论如何,本教程的一部分使用了 RecyclerView,我无法在我的 activity_main.xml 文件中访问它,说明 v7 是一个未解决的包。 android.support.v7.widget.RecyclerView 从 v7 开始显示为红色文本。我知道我可以将它恢复到旧版本,但我想我正在努力完成这项工作,因为它预计会知道如何使用 androidx 对吗?
我不知道如何将 RecyclerView 添加到我当前项目迁移到 androidx 的项目中。
我尝试过的:
根据文档添加实现 'com.android.support:recyclerview-v7:28.0.0' 使缓存无效并重新启动 我的依赖:
plugins
id 'com.android.application'
android
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig
applicationId "com.kdapps.videoplayer.hdmaxplayer.video.player"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
dependencies
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-process:2.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation "androidx.work:work-runtime:2.6.0"
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation 'com.google.android.gms:play-services-ads:19.8.0'
implementation 'com.facebook.android:audience-network-sdk:6.3.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.amitshekhar.android:android-networking:1.0.2'
implementation 'com.specyci:residemenu:1.6+'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
package com.kdapps.videoplayer.hdmaxplayer.video.player.Fragment;
import android.annotation.SuppressLint;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.kdapps.videoplayer.hdmaxplayer.video.player.Adapter.VideoAdapter;
import com.kdapps.videoplayer.hdmaxplayer.video.player.Model.EventBus;
import com.kdapps.videoplayer.hdmaxplayer.video.player.R;
import com.kdapps.videoplayer.hdmaxplayer.video.player.Util.VideoPlayerManager;
import com.kdapps.videoplayer.hdmaxplayer.video.player.Extra.MediaData;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
public class RecentFragment extends Fragment
@SuppressLint("StaticFieldLeak")
public static ImageView ivnodata;
public static RecyclerView recentrecycler;
ArrayList<MediaData> mediadataslist = new ArrayList<>();
private ProgressBar progress;
private View view;
@Override
public void onCreate(Bundle bundle)
super.onCreate(bundle);
org.greenrobot.eventbus.EventBus.getDefault().register(this);
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
this.view = layoutInflater.inflate(R.layout.fragment_recent, viewGroup, false);
@SuppressLint("WrongConstant")
NetworkInfo activeNetworkInfo = ((ConnectivityManager) getActivity().getSystemService("connectivity")).getActiveNetworkInfo();
if (activeNetworkInfo != null)
activeNetworkInfo.isConnected();
initView();
getVideo();
return this.view;
@Override
public void onDestroy()
super.onDestroy();
org.greenrobot.eventbus.EventBus.getDefault().unregister(this);
@SuppressLint("WrongConstant")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(EventBus event_Bus)
int type = event_Bus.getType();
if (type == 0)
initAdapter(this.mediadataslist, event_Bus.getValue());
else if (type == 1)
this.progress.setVisibility(0);
recentrecycler.setVisibility(8);
new Thread(new Runnable()
public void run()
RecentFragment.this.getVideo();
).start();
else if (type == 2)
int value = event_Bus.getValue();
if (value == 0)
Collections.sort(this.mediadataslist, new Comparator<MediaData>()
public int compare(MediaData media_Data, MediaData media_Data2)
return (Long.compare(Long.parseLong(media_Data2.getLength()), Long.parseLong(media_Data.getLength())));
);
initAdapter(this.mediadataslist, VideoPlayerManager.getViewBy());
else if (value == 1)
Collections.sort(this.mediadataslist, new Comparator<MediaData>()
public int compare(MediaData media_Data, MediaData media_Data2)
return Long.compare(Integer.parseInt(media_Data2.getDuration()), Integer.parseInt(media_Data.getDuration()));
);
initAdapter(this.mediadataslist, VideoPlayerManager.getViewBy());
else if (value == 2)
Collections.sort(this.mediadataslist, new Comparator<MediaData>()
public int compare(MediaData media_Data, MediaData media_Data2)
return media_Data.getName().compareTo(media_Data2.getName());
);
initAdapter(this.mediadataslist, VideoPlayerManager.getViewBy());
else if (value == 3)
Collections.sort(this.mediadataslist, new Comparator<MediaData>()
public int compare(MediaData media_Data, MediaData media_Data2)
return media_Data2.getModifieddate().compareTo(media_Data.getModifieddate());
);
initAdapter(this.mediadataslist, VideoPlayerManager.getViewBy());
else if (type == 3)
this.progress.setVisibility(0);
recentrecycler.setVisibility(8);
new Thread(new Runnable()
public void run()
RecentFragment.this.getVideo();
).start();
@SuppressLint("WrongConstant")
public void getVideo()
this.mediadataslist.clear();
if (!TextUtils.isEmpty(VideoPlayerManager.getRecentPlay()))
final ArrayList arrayList = (ArrayList) new Gson().fromJson(VideoPlayerManager.getRecentPlay(), new TypeToken<List<MediaData>>()
.getType());
Collections.reverse(arrayList);
this.mediadataslist.addAll(arrayList);
getActivity().runOnUiThread(new Runnable()
public void run()
RecentFragment.this.initAdapter(arrayList, VideoPlayerManager.getViewBy());
);
return;
this.progress.setVisibility(8);
recentrecycler.setVisibility(8);
ivnodata.setVisibility(0);
@SuppressLint("WrongConstant")
public void initAdapter(ArrayList<MediaData> arrayList, int i)
this.progress.setVisibility(8);
if (arrayList.size() > 0)
recentrecycler.setVisibility(0);
ivnodata.setVisibility(8);
VideoAdapter video_Adapter = new VideoAdapter(getActivity(), arrayList, i, 2);
if (i == 0)
recentrecycler.setLayoutManager(new LinearLayoutManager(getActivity(), 1, false));
else
recentrecycler.setLayoutManager(new GridLayoutManager((Context) getActivity(), 3, 1, false));
recentrecycler.setAdapter(video_Adapter);
return;
recentrecycler.setVisibility(8);
ivnodata.setVisibility(0);
private void initView()
recentrecycler = (RecyclerView) this.view.findViewById(R.id.hide_recycler);
progress = (ProgressBar) this.view.findViewById(R.id.progress);
ivnodata = (ImageView) this.view.findViewById(R.id.iv_nodata);
【问题讨论】:
您的标题具有误导性并且没有表达您的问题,在您的问题中您没有提到任何“视频”+ javascript 标签与 android 或 RecyclerView 无关。 【参考方案1】:v7 RecyclerView 现在是旧版,您应该改用 androidx 包。
为此,像这样将 androidx RecyclerView 依赖添加到 build.gradle(Module:app) 中
dependencies
...
implementation "androidx.recyclerview:recyclerview:1.2.1"
...
然后将其在 xml 布局中的头部名称更改为:
<androidx.recyclerview.widget.RecyclerView
... />
它会按预期工作。
注意:我的代码中的三个点 (...) 表示我不关心此处编写的代码,您应该包含您的代码。
有关如何处理 androidx RecyclerView 的更多信息,请查看Android Developers Tutorial
【讨论】:
以上是关于我在播放视频时遇到问题,它无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章
在同一视频标签上录制和播放时 MediaStream 关闭