update:修复圆角显示,封面缩略图拉伸
fix bug:
This commit is contained in:
2021-03-08 14:24:34 +08:00
parent 527587b926
commit a92df28f33
91 changed files with 557 additions and 68 deletions

View File

@@ -94,6 +94,7 @@ dependencies {
implementation 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
implementation 'tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.4'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
implementation 'com.github.SheHuan:NiceImageView:1.0.5'
implementation project(path: ':library')
// implementation 'com.github.SheHuan:NiceImageView:1.0.5'
implementation project(path: ':JZVideo')
implementation project(path: ':niceimageview')
}

View File

@@ -48,9 +48,10 @@ public class MainActivity extends AppCompatActivity {
String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
private RecyclerView recyclerView;
private TextView tips;
private TextView tips, tv_scan;
private SwipeRefreshLayout refreshLayout;
private VideoAdapter adapter;
private List<String> paths = new ArrayList<>();
private RecycleGridLayoutManager mManager;
@@ -62,6 +63,7 @@ public class MainActivity extends AppCompatActivity {
initView();
// String rootPath = Environment.getExternalStorageDirectory().getPath() + File.separator;
// traverseFolder(rootPath);
ScanTask scanTask = new ScanTask();
scanTask.execute();
}
@@ -89,6 +91,7 @@ public class MainActivity extends AppCompatActivity {
private void initView() {
initActionBar();
tips = findViewById(R.id.tips);
tv_scan = findViewById(R.id.tv_scan);
refreshLayout = findViewById(R.id.swipeRefreshLayout);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
@@ -111,6 +114,8 @@ public class MainActivity extends AppCompatActivity {
recyclerView.addItemDecoration(new SpacesItemDecoration(getResources().getDimensionPixelSize(R.dimen.PX1x), getResources().getDimensionPixelSize(R.dimen.PX1x),
getResources().getDimensionPixelSize(R.dimen.PX1x), getResources().getDimensionPixelSize(R.dimen.PX1x)));
((DefaultItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
adapter = new VideoAdapter(MainActivity.this);
recyclerView.setAdapter(adapter);
}
private void initActionBar() {
@@ -198,6 +203,8 @@ public class MainActivity extends AppCompatActivity {
@Override
protected List<String> doInBackground(Void... voids) {
long s1 = System.currentTimeMillis();
paths.clear();
List<String> fileList = new ArrayList<>();
String rootPath = Environment.getExternalStorageDirectory().getPath() + File.separator;
File file = new File(rootPath);
@@ -232,6 +239,7 @@ public class MainActivity extends AppCompatActivity {
} else {
Log.e("traverseFolder1", "文件不存在!");
}
Log.e("ScanTask", "doInBackground: " + "Scan time = " + (System.currentTimeMillis() - s1) + "ms");
return fileList;
}
@@ -239,22 +247,26 @@ public class MainActivity extends AppCompatActivity {
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
// Log.e("ScanTask", "onProgressUpdate: " + values[0]);
paths.add(values[0]);
tv_scan.setVisibility(View.VISIBLE);
tv_scan.setText("正在扫描:" + values[0]);
adapter.setData(paths);
}
@Override
protected void onPostExecute(List<String> strings) {
super.onPostExecute(strings);
Log.e("ScanTask", "onPostExecute: " + strings);
Log.e("ScanTask", "onPostExecute: " + strings.size());
if (strings.size() == 0) {
tips.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
tips.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
adapter = new VideoAdapter(MainActivity.this, strings);
adapter.setData(strings);
// recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
recyclerView.setAdapter(adapter);
}
tv_scan.setVisibility(View.GONE);
refreshLayout.setRefreshing(false);
}
}

View File

@@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.media.MediaMetadataRetriever;
import android.os.AsyncTask;
@@ -17,10 +18,13 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.shehuan.niv.NiceImageView;
import com.uiui.videoplayer.R;
import com.uiui.videoplayer.activity.ActivityTikTok;
@@ -65,6 +69,11 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder>
Bitmap frame;
}
public void setData(List<String> paths) {
this.videoPath = paths;
notifyDataSetChanged();
}
@NonNull
@Override
public VideoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@@ -76,61 +85,66 @@ public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.VideoHolder>
public void onBindViewHolder(@NonNull final VideoHolder holder, final int position) {
final String path = videoPath.get(position);
File file = new File(path);
if (file.exists() && file.isFile()) {
// if (file.exists() && file.isFile()) {
// BitmapRetultListener bitmapRetultListener = new BitmapRetultListener() {
// @Override
// public void onScanCompleted(Bitmap bitmap) {
// Glide.with(holder.video_image).load(bitmap).into(holder.video_image);
// }
// };
Observable.create(new ObservableOnSubscribe<VideoResult>() {
@Override
public void subscribe(ObservableEmitter<VideoResult> emitter) throws Exception {
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(path);
String duration = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
Bitmap bitmap = mmr.getFrameAtTime();//获得视频第一帧的Bitmap对象.
Long time = Long.valueOf(duration);
Observable.create(new ObservableOnSubscribe<VideoResult>() {
@Override
public void subscribe(ObservableEmitter<VideoResult> emitter) throws Exception {
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(path);
String duration = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);
Bitmap bitmap = mmr.getFrameAtTime();//获得视频第一帧的Bitmap对象.
Long time = Long.valueOf(duration);
mmr.release();
VideoResult result = new VideoResult();
result.frame = bitmap;
result.time = time;
emitter.onNext(result);
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<VideoResult>() {
@Override
public void onSubscribe(Disposable d) {
mmr.release();
VideoResult result = new VideoResult();
result.frame = bitmap;
result.time = time;
emitter.onNext(result);
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<VideoResult>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(VideoResult result) {
try {
Glide.with(holder.video_image).load(result.frame).skipMemoryCache(false).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
holder.video_image.setImageDrawable(resource);
}
});
holder.duration.setText(Utils.TimeFormat(result.time));
} catch (Exception e) {
}
}
@Override
public void onNext(VideoResult result) {
try {
Glide.with(holder.video_image).load(result.frame).into(holder.video_image);
holder.duration.setText(Utils.TimeFormat(result.time));
} catch (Exception e) {
@Override
public void onError(Throwable e) {
}
}
}
@Override
public void onError(Throwable e) {
@Override
public void onComplete() {
}
@Override
public void onComplete() {
}
});
}
});
// this.listener = bitmapRetultListener;
holder.title.setText(getFileName(path));
Log.e("title:", holder.title.getText().toString());
}
holder.title.setText(getFileName(path));
Log.e("title:", holder.title.getText().toString());
// }
holder.root.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

View File

@@ -1,23 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_scan">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:background="@color/white">
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/tips"
@@ -27,7 +36,21 @@
android:text="没有找到视频文件"
android:textColor="@color/defaultColor"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tv_scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:text=""
android:singleLine="true"
android:textColor="@color/defaultColor"
android:textSize="18sp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,24 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_scan">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:background="@color/white">
</androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<TextView
android:id="@+id/tips"
@@ -28,7 +36,21 @@
android:text="没有找到视频文件"
android:textColor="@color/defaultColor"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tv_scan"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:text=""
android:singleLine="true"
android:textColor="@color/defaultColor"
android:textSize="18sp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -12,12 +12,11 @@
android:layout_height="162dp"
android:layout_marginTop="4dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:scaleType="centerCrop"
app:is_cover_src="true"
app:corner_radius="5dp"
android:background="@color/black"
app:corner_radius="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintHorizontal_bias="0.500"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />