Skip to content

Commit d93a159

Browse files
committed
Merge remote-tracking branch 'origin/hss/onlyglide' into hss/onlyglide
2 parents 810b96b + 79cbd08 commit d93a159

File tree

23 files changed

+359
-170
lines changed

23 files changed

+359
-170
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ dependencies {
108108
api('com.davemorrissey.labs:subsampling-scale-image-view:3.10.0') {
109109
exclude group: 'com.android.support'
110110
}
111+
api "com.github.hss01248.media:localvideoplayer:1.0.0"
111112

112113
}
113114

app/src/main/java/com/hss01248/imageloaderdemo/MainActivity.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.hss01248.imageloaderdemo;
22

3-
import android.Manifest;
43
import android.app.Activity;
54
import android.app.Dialog;
65
import android.content.Context;
@@ -26,7 +25,6 @@
2625

2726
import com.blankj.utilcode.util.AppUtils;
2827
import com.blankj.utilcode.util.LogUtils;
29-
import com.blankj.utilcode.util.PermissionUtils;
3028
import com.blankj.utilcode.util.ThreadUtils;
3129
import com.blankj.utilcode.util.ToastUtils;
3230
import com.bumptech.glide.Glide;
@@ -217,21 +215,7 @@ public void onClick(View view) {
217215
pid=31500, uid=10576 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()*/
218216

219217

220-
PermissionUtils.permission(Manifest.permission.WRITE_EXTERNAL_STORAGE).callback(new PermissionUtils.SingleCallback() {
221-
@Override
222-
public void callback(boolean isAllGranted, @NonNull List<String> granted, @NonNull List<String> deniedForever, @NonNull List<String> denied) {
223-
224-
ImageMediaCenterUtil.showViewAsActivity(MainActivity.this, new IViewInit() {
225-
@Override
226-
public View init(Activity activity) {
227-
ImageListView view1 = new ImageListView(activity);
228-
view1.showAllAlbums();
229-
return view1;
230-
}
231-
});
232-
233-
}
234-
}).request();
218+
ImageMediaCenterUtil.showAlbums();
235219

236220

237221
}

bigimageviewpager/src/main/java/com/hss01248/bigimageviewpager/LargeImageViewer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static void showOne(String path){
103103
public void accept(Pair<ContainerActivity2, ContainerViewHolderWithTitleBar> pair) throws Exception {
104104

105105
MyLargeImageViewBySubSamplingView largeImageView = new MyLargeImageViewBySubSamplingView(pair.first);
106-
largeImageView.loadUri(path);
106+
largeImageView.loadUri(path,true);
107107
pair.second.getBinding().llRoot.setBackgroundColor(Color.BLACK);
108108
pair.second.getBinding().rlContainer.addView(largeImageView);
109109

@@ -156,7 +156,7 @@ public static void showInDialog(String path){
156156
LogUtils.d("path to load: "+ path);
157157
MyLargeImageViewBySubSamplingView largeImageView = new MyLargeImageViewBySubSamplingView(ActivityUtils.getTopActivity());
158158
FullScreenDialogUtil.showFullScreen(largeImageView);
159-
largeImageView.loadUri(path);
159+
largeImageView.loadUri(path,true);
160160
}
161161

162162

@@ -202,15 +202,15 @@ public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
202202
@NonNull
203203
@Override
204204
public Object instantiateItem(@NonNull ViewGroup container, int position) {
205-
MyLargeImageView imageView = null;
205+
MyLargeImageViewBySubSamplingView imageView = null;
206206
if(cacheList.isEmpty()){
207-
imageView = new MyLargeImageView(context);
207+
imageView = new MyLargeImageViewBySubSamplingView(context);
208208
}else {
209-
imageView = (MyLargeImageView) cacheList.remove(0);
209+
imageView = (MyLargeImageViewBySubSamplingView) cacheList.remove(0);
210210
}
211211
String url = uris.get(position);
212212
url = getBigImageUrl(url);
213-
imageView.loadUri(url);
213+
imageView.loadUri(url,true);
214214
container.addView(imageView);
215215
return imageView;
216216
}

bigimageviewpager/src/main/java/com/hss01248/bigimageviewpager/MyLargeImageView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import io.reactivex.functions.Function;
5454
import io.reactivex.schedulers.Schedulers;
5555

56+
@Deprecated
5657
public class MyLargeImageView extends FrameLayout {
5758
MyGifPhotoView gifView;
5859
MyLargeJpgView jpgView;

bigimageviewpager/src/main/java/com/hss01248/bigimageviewpager/MyLargeImageViewBySubSamplingView.java

Lines changed: 149 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
import androidx.annotation.NonNull;
1919
import androidx.annotation.Nullable;
2020
import androidx.annotation.RequiresApi;
21+
import androidx.media3.common.MediaItem;
22+
import androidx.media3.common.PlaybackException;
23+
import androidx.media3.common.Player;
24+
import androidx.media3.exoplayer.ExoPlayer;
25+
import androidx.media3.ui.PlayerView;
2126

2227
import com.blankj.utilcode.util.AppUtils;
2328
import com.blankj.utilcode.util.LogUtils;
@@ -31,6 +36,7 @@
3136
import com.hss01248.bigimageviewpager.photoview.MyGifPhotoView;
3237
import com.hss01248.glide.aop.file.AddByteUtil;
3338
import com.hss01248.media.metadata.ExifUtil;
39+
import com.hss01248.motion_photos.MotionPhotoUtil;
3440
import com.hss01248.viewstate.StatefulLayout;
3541
import com.hss01248.viewstate.ViewStateConfig;
3642
import com.tencent.qcloud.image.avif.subsampling.AvifSubsamplingImageDecoder;
@@ -88,7 +94,7 @@ public MyLargeImageViewBySubSamplingView(@NonNull Context context) {
8894
}
8995

9096
}
91-
97+
ImageView ivPlayVideo;
9298
private void init(Context context) {
9399
stateBinding = StateItemLargeImgSubsamplingBinding.inflate(LayoutInflater.from(context),this,true);
94100
largeImgBinding = stateBinding.itemLargeImg;
@@ -107,6 +113,8 @@ public void run() {
107113
tvScale = largeImgBinding.tvScale;
108114
jpgView = largeImgBinding.ivLarge;
109115
gifView = largeImgBinding.gifLarge;
116+
ivPlayVideo = stateBinding.itemLargeImg.ivPlayVideo;
117+
playerView = stateBinding.itemLargeImg.playView;
110118
jpgView.setDebug(AppUtils.isAppDebug());
111119
jpgView.setMaxScale(12);
112120

@@ -183,7 +191,7 @@ public void setOritation(boolean isLandscape, boolean fromConfigChange){
183191
}
184192

185193
private void reload() {
186-
loadUri(info.uri);
194+
loadUri(info.uri,true);
187195

188196
}
189197

@@ -210,7 +218,7 @@ public void setOnClickListener(@Nullable OnClickListener l) {
210218
}
211219
}
212220

213-
private void loadUrl(String url) {
221+
private void loadUrl(String url, boolean loadMotionVideo) {
214222

215223
stateManager.showLoading();
216224

@@ -245,35 +253,35 @@ public void onFail(Throwable throwable) {
245253

246254
}
247255

248-
private void loadFile(String filePath) {
249-
loadFile(filePath, false);
256+
private void loadFile(String filePath, boolean loadMotionVideo) {
257+
loadFile(filePath, false,loadMotionVideo);
250258
}
251259

252-
private void loadFile(String filePath, boolean isGif) {
253-
loadLocal(filePath, isGif);
260+
private void loadFile(String filePath, boolean isGif, boolean loadMotionVideo) {
261+
loadLocal(filePath, isGif,loadMotionVideo);
254262
}
255263

256264
private void toastMsg(String message) {
257265
Toast.makeText(getContext().getApplicationContext(), message, Toast.LENGTH_LONG).show();
258266
}
259267

260-
public void loadUri(String uri) {
268+
public void loadUri(String uri, boolean loadMotionVideo) {
261269
info.uri = uri;
262270
//if(uri.startsWith("file://") || uri.startsWith("/storage/"))
263271
if (uri.startsWith("http")) {
264-
loadUrl(uri);
272+
loadUrl(uri,loadMotionVideo);
265273
return;
266274
}
267275
if (uri.startsWith("/storage/")) {
268-
loadFile(uri, false);
276+
loadFile(uri, false,loadMotionVideo);
269277
return;
270278
}
271279
if (uri.startsWith("file://")) {
272-
loadFile(uri.substring("file://".length()), false);
280+
loadFile(uri.substring("file://".length()), false,loadMotionVideo);
273281
return;
274282
}
275283
if (uri.startsWith("content://")) {
276-
loadLocal(uri, false);
284+
loadLocal(uri, false,loadMotionVideo);
277285
return;
278286
}
279287
}
@@ -286,9 +294,30 @@ public String getInfoStr(){
286294
return info.getInfo();
287295
}
288296

289-
private void loadLocal(String uri, boolean isGif) {
297+
PlayerView playerView;
298+
299+
private void loadLocal(String uri, boolean isGif, boolean loadMotionVideo) {
290300
info.localPathOrUri = uri;
291301
largeImgBinding.ivGo360.setVisibility(GONE);
302+
// stateBinding.stateLayout.showContent();
303+
stateManager.showContent();
304+
if( MotionPhotoUtil.isMotionImage(uri,false)){
305+
if(loadMotionVideo){
306+
loadMotionVideo(uri);
307+
return;
308+
}
309+
ivPlayVideo.setVisibility(VISIBLE);
310+
ivPlayVideo.setOnClickListener(new OnClickListener() {
311+
@Override
312+
public void onClick(View view) {
313+
loadLocal(info.localPathOrUri,isGif,true);
314+
}
315+
});
316+
317+
}else {
318+
ivPlayVideo.setVisibility(GONE);
319+
}
320+
292321
if (uri.contains(".gif") || isGif) {
293322
gifView.setVisibility(VISIBLE);
294323
jpgView.setVisibility(GONE);
@@ -301,6 +330,21 @@ private void loadLocal(String uri, boolean isGif) {
301330
}
302331
stateManager.showContent();
303332
} else {
333+
if(MotionPhotoUtil.isMotionImage(uri,false) ){
334+
if(playerView.getVisibility() != View.GONE){
335+
LargeImageViewer.fadeToGone(playerView,500);
336+
}
337+
ivHelper.setVisibility(VISIBLE);
338+
ivHelper.setOnClickListener(new OnClickListener() {
339+
@Override
340+
public void onClick(View view) {
341+
loadLocal(info.localPathOrUri, isGif, true);
342+
}
343+
});
344+
345+
}else {
346+
playerView.setVisibility(View.GONE);
347+
}
304348
gifView.setVisibility(GONE);
305349
jpgView.setVisibility(VISIBLE);
306350
//兼容avif格式
@@ -333,6 +377,96 @@ private void loadLocal(String uri, boolean isGif) {
333377
}
334378
}
335379

380+
381+
ExoPlayer player;
382+
Player.Listener listener;
383+
private void loadMotionVideo(String uri) {
384+
String motionVideoPath = MotionPhotoUtil.getMotionVideoPath(uri);
385+
if(motionVideoPath ==null || motionVideoPath.equals("")){
386+
return;
387+
}
388+
ivHelper.setVisibility(GONE);
389+
playerView.setVisibility(VISIBLE);
390+
gifView.setVisibility(GONE);
391+
LargeImageViewer.fadeToGone(jpgView,300);
392+
//jpgView.setVisibility(GONE);
393+
File file = new File(motionVideoPath);
394+
395+
if(player !=null){
396+
if(player.isPlaying()){
397+
player.stop();
398+
}else if(player.isLoading()){
399+
player.stop();
400+
}
401+
player.release();
402+
player = null;
403+
}
404+
405+
player = new ExoPlayer.Builder(getContext())
406+
.build();
407+
playerView.setPlayer(player);
408+
listener = new Player.Listener() {
409+
@Override
410+
public void onPlaybackStateChanged(int playbackState) {
411+
Player.Listener.super.onPlaybackStateChanged(playbackState);
412+
if(playbackState == Player.STATE_ENDED ){
413+
loadLocal(uri,false,false);
414+
}
415+
}
416+
417+
@Override
418+
public void onPlayerError(PlaybackException error) {
419+
Player.Listener.super.onPlayerError(error);
420+
LogUtils.w(error);
421+
loadLocal(uri,false,false);
422+
}
423+
};
424+
player.addListener(listener);
425+
player.setPlayWhenReady(true);
426+
player.setRepeatMode(Player.REPEAT_MODE_OFF);
427+
428+
429+
//sending message to a Handler on a dead thread
430+
try{
431+
//IllegalStateException: Handler (android.os.Handler) {674e76a} sending message to a Handler on a dead thread
432+
player.setMediaItem(MediaItem.fromUri(Uri.fromFile(file)));
433+
player.prepare();
434+
}catch (Throwable throwable){
435+
LogUtils.w(throwable);
436+
player.release();
437+
player = null;
438+
loadLocal(uri,false,false);
439+
}
440+
441+
}
442+
443+
public void pausePlayer(){
444+
if(player !=null){
445+
if(player.isPlaying() || player.isLoading()){
446+
player.stop();
447+
}
448+
player.release();
449+
player = null;
450+
}
451+
}
452+
453+
@Override
454+
protected void onDetachedFromWindow() {
455+
super.onDetachedFromWindow();
456+
LogUtils.w("onDetachedFromWindow-"+this);
457+
try {
458+
if(player !=null){
459+
if(player.isPlaying()){
460+
player.stop();
461+
}
462+
player.release();
463+
}
464+
}catch (Throwable throwable){
465+
LogUtils.w(throwable);
466+
}
467+
468+
}
469+
336470
public static boolean isPanoramaImage(String path){
337471
Map<String, String> map = ExifUtil.readExif(path);
338472
String xml = map.get("Xmp");
@@ -341,10 +475,10 @@ public static boolean isPanoramaImage(String path){
341475
LogUtils.i("根据exif特征识别出为360全景图,不进行压缩");
342476
return true;
343477
}
344-
if(xml.contains("MotionPhoto")){
478+
/*if(xml.contains("MotionPhoto")){
345479
LogUtils.i("根据exif特征识别出为MotionPhoto,不进行压缩");
346480
return true;
347-
}
481+
}*/
348482
//MotionPhoto
349483
}
350484
return false;

0 commit comments

Comments
 (0)