На самом деле я сделал галерею, в которой есть коллекция фотографий и видео, я могу добавить встроенные видеоролики youtube, полученные с сервера, в веб-просмотр, определенный в классе адаптера (VideoAdapter. java), но когда я пытаюсь чтобы перейти в полноэкранный режим видео, приложение вылетает с этой ошибкой:
2020-05-06 02:11:16.684 12502-12502/com.fitness.client A/chromium: [FATAL:jni_android.cc(249)] Please include Java exception stack in crash report
2020-05-06 02:11:18.540 12502-12502/com.fitness.client A/libc: Fatal signal 5 (SIGTRAP), code -6 (SI_TKILL) in tid 12502 (.fitness.client), pid 12502 (.fitness.client)
для решения этой проблемы Я нашел эту ссылку но как мы можем вызвать onDestroyView () внутри адаптера . Вот демонстрация
Может ли кто-нибудь помочь мне решить эту проблему, чтобы я мог также воспроизводить видео в полноэкранном режиме?
Вот код VideoAdapter. java
package com.fitness.client.ui.main.fragments.gallery.adapter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.MediaController;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.fitness.client.App;
import com.fitness.client.R;
import com.fitness.client.api.RetroFitFactory;
import com.fitness.client.api.user.DeleteGalleryResponse;
import com.fitness.client.api.user.GalleryResponse;
import com.fitness.client.api.user.UserService;
import com.fitness.client.base.classes.BaseRecyclerViewAdapter;
import com.fitness.client.base.classes.BaseViewHolder;
import com.fitness.client.databinding.ItemProfileVideoBinding;
import com.fitness.client.ui.Main;
import com.fitness.client.ui.main.MainActivity;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class VideoAdapter extends BaseRecyclerViewAdapter<VideoAdapter.VideoHolder, GalleryResponse.Video_galleryEntity> {
Context context;
private ArrayList<GalleryResponse.Video_galleryEntity> getVideoObject;
public VideoAdapter(Context context, ArrayList<GalleryResponse.Video_galleryEntity> data) {
super(data);
getVideoObject = data;
this.context = context;
}
@NonNull
@Override
public VideoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new VideoHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_profile_video, parent, false));
}
class VideoHolder extends BaseViewHolder<GalleryResponse.Video_galleryEntity, ItemProfileVideoBinding> {
public VideoHolder(View itemView) {
super(itemView);
}
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void bindObject(GalleryResponse.Video_galleryEntity object) {
// getViewDataBinding().videoText.setText(object.getVideo_type());
ProgressDialog progress = new ProgressDialog(getContext());
progress.setMessage("Please Wait...");
progress.setCancelable(false);
//Getting video
String video_url = object.getVideo();
Log.e("MyFragment", "video-url: " + video_url);
getViewDataBinding().video.getSettings().setJavaScriptEnabled(true);
getViewDataBinding().video.setWebChromeClient(new ChromeClient());
String newUrl = "<iframe src=\"" + video_url + "\" width=\"100%\" height=\"500\" style=\"border:none;overflow:hidden\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\" allowfullscreen></iframe>" ;
MediaController controller = new MediaController(getContext());
controller.setAnchorView(getViewDataBinding().video);
getViewDataBinding().video.loadData(newUrl, "text/html", "utf-8");
getViewDataBinding().deletevideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("Do you want to delete this Video?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//TODO: Add delete image functionality
progress.show();
RetroFitFactory.getRetrofitCallFor(UserService.class)
.deleteGallery(object.getId())
.enqueue(new Callback<DeleteGalleryResponse>() {
@Override
public void onResponse(@NonNull Call<DeleteGalleryResponse> call, @NonNull Response<DeleteGalleryResponse> response) {
if (response.isSuccessful() && response.body() != null) {
// Toast.makeText(context, response.body().getMessage(), Toast.LENGTH_SHORT).show();
if (response.body().getSuccess()) {
progress.dismiss();
getVideoObject.remove(getAdapterPosition());
Toast.makeText(context, "Video deleted successfully", Toast.LENGTH_SHORT).show();
notifyDataSetChanged();
}
} else {
Toast.makeText(context, "Some Error...", Toast.LENGTH_SHORT).show();
}
progress.dismiss();
}
@Override
public void onFailure(@NonNull Call<DeleteGalleryResponse> call, @NonNull Throwable t) {
Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show();
Log.e("On Image Error", "onFailure: " + t.getMessage());
progress.dismiss();
}
});
}
});
builder.setNegativeButton("NO", null);
AlertDialog alertDialog = builder.create();
alertDialog.show();
Button buttonyes = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
buttonyes.setBackgroundColor(Color.BLACK);
buttonyes.setPadding(0, 0, 20, 0);
buttonyes.setTextColor(Color.WHITE);
// Button buttonNo = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
// buttonNo.setBackgroundColor(Color.BLACK);
// buttonNo.setPadding(0, 0, 20, 0);
// buttonNo.setTextColor(Color.WHITE);
}
});
}
private class ChromeClient extends WebChromeClient {
Activity activity = new MainActivity(); ***//This line causes the problem***
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
ChromeClient() {}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(context.getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)activity.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
activity.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
activity.setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility =activity.getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = activity.getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)activity.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
activity.getWindow().getDecorView().setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
}
}
}
Заранее спасибо.