更高版本的Android Video View问题

时间:2017-07-20 10:44:53

标签: android android-videoview

我正在尝试在videoview中查看录制的视频。功能工作者在Marshmallow下面的Android版本中很好,但在它们之上的版本中给出了错误。 enter image description here

视频预览的代码是:

 public static byte[] GeneratePDF(string pdfPath, Dictionary<string, string> formFieldMap)
            {
                var output = new MemoryStream();
                var reader = new PdfReader(pdfPath);
                var stamper = new PdfStamper(reader, output);
                var formFields = stamper.AcroFields;
                foreach (var fieldName in formFieldMap.Keys)
                {
                    if (formFieldMap[fieldName] != null)
                    {
                        formFields.SetField(fieldName, formFieldMap[fieldName]);
                    }
                }
                stamper.FormFlattening = true;
                stamper.Close();
                reader.Close();

                return output.ToArray();
            }

记录:

private void previewMedia(boolean isImage) {
        // Checking whether captured media is image or video
        vidPreview.setVisibility(View.VISIBLE);
        String uriPath =  filePath;
        MediaController mediacontroller = new MediaController(
                UploadActivity.this);
        mediacontroller.setAnchorView(vidPreview);
        if (CommonMethods.androidVersionCheck() == true) {
            Uri photoURI = Uri.fromFile((new File(Environment.getExternalStorageDirectory()
                    .getAbsolutePath(),uriPath)));
            boolean result = PermissionRequest.checkPermission(this);
            if (result){
                vidPreview.setVideoURI(photoURI);
            }else CommonMethods.AlertTitle("Permission Denied",this);
        }else {
            Uri uri = Uri.parse(uriPath);
            vidPreview.setVideoURI(uri);
        }
        vidPreview.setMediaController(mediacontroller);
        vidPreview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {
                vidPreview.start();
            }
        });
        /*vidPreview.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.d("video", "setOnErrorListener ");
                return true;
            }
        });*/
    }

1 个答案:

答案 0 :(得分:0)

  

从Android 6.0(API级别23)开始,用户授予权限   应用程序运行时的应用程序,而非安装应用程序时的应用程序。

换句话说,您需要在应用程序中请求权限。 AndroidManifest还不够。

检查更多信息和样本: https://developer.android.com/training/permissions/requesting.html