1

在 react-native-video 中,当 react-native run-android 发生这些错误,我无法删除这些

android.useAndroidX=true android.enableJetifier=true 来自 gradle.properties

我需要它们来响应本机手势处理程序

尝试添加实现 'androidx.appcompat:appcompat:${rootProject.ext.supportLibVersion}'

但它不起作用

在此处输入图像描述

package com.sales_crm;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

public class VideoActivity extends AppCompatActivity {
    private String videoPath;

    private static ProgressDialog progressDialog;
    VideoView myVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
        setContentView(R.layout.player_fullscreen);
        Intent i = getIntent();
        if(i != null){
            myVideoView = (VideoView) findViewById(R.id.videoView);
            videoPath = i.getStringExtra("VIDEO_URL");
            progressDialog = ProgressDialog.show(VideoActivity.this, "", "Buffering video...", true);
            progressDialog.setCancelable(true);
            PlayVideo();
        }
        else{
            Toast.makeText(VideoActivity.this, "VideoURL not found", Toast.LENGTH_SHORT).show();
        }


    }

    private void PlayVideo() {
        try {
            getWindow().setFormat(PixelFormat.TRANSLUCENT);
            MediaController mediaController = new MediaController(VideoActivity.this);
            mediaController.setAnchorView(myVideoView);

            Uri video = Uri.parse(videoPath);
            myVideoView.setMediaController(mediaController);
            myVideoView.setVideoURI(video);
            myVideoView.requestFocus();
            myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {
                    progressDialog.dismiss();
                    if(BridgeModule.duration!=0)
                     myVideoView.seekTo(BridgeModule.duration);
                    myVideoView.start();
                }
            });


        } catch (Exception e) {
            progressDialog.dismiss();
            System.out.println("Video Play Error :" + e.toString());
            finish();
        }

    }
}

我的依赖

dependencies {
    implementation project(':react-native-share')
    implementation project(':react-native-sound')
    implementation project(':react-native-sound-player')
    implementation project(':react-native-orientation-locker')
    implementation project(':react-native-document-picker')
    implementation project(':react-native-image-picker')
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-pdf')
    implementation project(':react-native-maps')
    implementation project(':react-native-video')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-gesture-handler')
    implementation project(':@react-native-community_async-storage')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

}
4

1 回答 1

3

首先,请使用以下命令安装 jetifier:

npm install --save-dev jetifier

之后请运行以下命令:

npx jetify

您可以将此脚本添加到您的package.json

"scripts": {
  "postinstall": "npx jetify"
}
于 2019-09-11T14:47:32.600 回答