播放完后停在第一帧(缺少大小+再次播放逻辑)

This commit is contained in:
liujing
2020-10-19 21:03:58 +08:00
parent c418ac9a5a
commit afca3396fc
3 changed files with 47 additions and 18 deletions

View File

@@ -28,6 +28,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@@ -645,7 +646,12 @@ public class BitmapHelper {
Bitmap b = null;
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource( filePath );
retriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
retriever.setDataSource(filePath, new HashMap<String, String>());
else
retriever.setDataSource(filePath);
// mediaMetadataRetriever.setDataSource(videoPath);
b = retriever.getFrameAtTime();
} catch ( IllegalArgumentException e ) {
e.printStackTrace();

View File

@@ -1,33 +1,27 @@
package com.mogo.module.v2x.scenario.scene.road;
import android.content.Context;
import android.net.Uri;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.mogo.map.IDestroyable;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerExploreWayItem;
import com.mogo.module.common.entity.V2XEventShowEntity;
import com.mogo.module.common.entity.V2XMessageEntity;
import com.mogo.module.common.entity.V2XRoadEventEntity;
import com.mogo.module.v2x.R;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.listener.V2XWindowStatusListener;
import com.mogo.module.v2x.scenario.view.IV2XWindow;
import com.mogo.module.v2x.view.TextureVideoView;
import com.mogo.service.imageloader.MogoImageView;
import com.mogo.utils.BitmapHelper;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import retrofit2.http.Url;
import static com.mogo.module.v2x.V2XConst.MODULE_NAME;
@@ -37,6 +31,8 @@ public class V2XRoadVideoWindow extends RelativeLayout implements IV2XWindow, ID
private V2XWindowStatusListener mV2XWindowStatusListener;
private TextureVideoView mVideoView;
private ImageView closeImage;
private ImageView mThumbnailImageView;
private ImageView windowPalyImageView;
public V2XRoadVideoWindow() {
this(V2XServiceManager.getContext(), null);
@@ -59,6 +55,8 @@ public class V2XRoadVideoWindow extends RelativeLayout implements IV2XWindow, ID
LayoutInflater.from(context).inflate(R.layout.window_road_video, this);
mVideoView = findViewById(R.id.roadVideoView);
closeImage = findViewById(R.id.roadVideoClose);
mThumbnailImageView = findViewById(R.id.thumbnail_image);
windowPalyImageView = findViewById(R.id.window_video_play);
closeImage.setOnClickListener(v -> {
close();
});
@@ -76,23 +74,43 @@ public class V2XRoadVideoWindow extends RelativeLayout implements IV2XWindow, ID
return;
}
if (path.contains(".mp4")) {
mVideoView.setVisibility(VISIBLE);
mVideoView.setVideoPath(path);
mVideoView.setOnPreparedListener(mediaPlayer -> {
Logger.w(MODULE_NAME, "全屏准备。。。。。");
});
videoViewStartWithPath(path);
mVideoView.setOnCompletionListener(mediaPlayer -> {
Logger.w(MODULE_NAME, "全屏展示结束...");
Logger.w(MODULE_NAME, "视频播放结束...");
Bitmap bitmap = BitmapHelper.getVideoThumbnail(path);
mThumbnailImageView.setVisibility(View.VISIBLE);
mThumbnailImageView.setImageBitmap(bitmap);
windowPalyImageView.setVisibility(View.VISIBLE);
windowPalyImageView.setOnClickListener(v -> {
videoViewStartWithPath(path);
});
if (mV2XWindowStatusListener != null) {
mV2XWindowStatusListener.onViewClose();
}
});
mVideoView.start();
}
}
}
/*
* 视频开始播放
* */
private void videoViewStartWithPath(String path) {
mVideoView.setVisibility(VISIBLE);
mVideoView.setVideoPath(path);
mVideoView.setOnPreparedListener(mediaPlayer -> {
Logger.w(MODULE_NAME, "全屏准备。。。。。");
mThumbnailImageView.setVisibility(View.GONE);
windowPalyImageView.setVisibility(View.GONE);
});
}
@Override
public void close() {
//移除窗体

View File

@@ -20,7 +20,6 @@
android:layout_height="match_parent"
android:background="@color/live_video_progress_bar_loading_color"
android:clickable="false"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -29,16 +28,22 @@
</com.mogo.module.v2x.view.TextureVideoView>
<com.mogo.service.imageloader.MogoImageView
android:id="@+id/big_image"
android:id="@+id/thumbnail_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/dp_30"
android:background="@drawable/v2x_bg_big_image_dark"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/window_video_play"
android:layout_width="@dimen/dp_100"
android:layout_height="@dimen/dp_100"
android:layout_centerInParent="true"
android:visibility="gone"
android:src="@drawable/v2x_icon_event_play"/>
</com.mogo.module.v2x.view.RoundLayout>
<ImageView
android:id="@+id/roadVideoClose"