HBiSoft / HBRecorder

Lightweight screen recording Android library
MIT License
402 stars 137 forks source link

Unable to share video on Whatsapp #152

Closed anshu-mittal closed 8 months ago

anshu-mittal commented 9 months ago

READ THIS BEFORE OPENING AN ISSUE:

Describe the bug I record screen using this library and on sharing the video over whatsapp, I get this message - "Can't send this video. Choose a different video and try again."

Can it be reproduced in demo app No

HBRecorder version for example 3.0.1

Device information

Additional details - I tried mailing the video, it works if I download the video in mail and play it using Photos app.

Code:

    private HBRecorder hbRecorder = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        .... other code
        hbRecorder = new HBRecorder(this, recorderListener);
        hbRecorder.isAudioEnabled(false);
        .... other code
    }
    private void startRecording() {
        final String path = getVideoPath(this);
        if (path != null) {
            hbRecorder.setOutputPath(path);
            MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
            Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
            startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
        } else {
            Toast.makeText(MapsActivity.this, "Cannot start the recording, file path issue", Toast.LENGTH_LONG).show();
        }
    }

    fun shareVideo(path: File, context: Context) {
        val uri = FileProvider.getUriForFile(context,
            context.getString(R.string.file_provider_authority), path)
        val shareIntent = Intent(Intent.ACTION_SEND)
            .setType("video/*")
            .putExtra(Intent.EXTRA_STREAM, uri)
        context.startActivity(shareIntent)
    }

        @Override
        public void HBRecorderOnComplete() {
           //with other code
            String filePath = hbRecorder.getFilePath();
            shareVideo(new File(filePath), this);
           //with other code
        }

        fun getVideoPath(context: Context): String? {
            val myFolder = "/MyAppsDirectory"
            val file: File = if (SDK_INT >= R) {
                val path = context.getExternalFilesDir(DIRECTORY_MOVIES)?.absolutePath
                path?.let {
                    File(path + myFolder)
                } ?: run {
                    return null
                }
            } else {
                File(getExternalStorageDirectory().toString() + myFolder)
            }
            if (!file.exists()) {
                file.mkdir()
            }
            return file.absolutePath
        }

*sorry about the kotlin and java mix.

I would really appreciate any help. It may not be an HBRecorder issue but if you can point towards the issue. I believe it may be a video codec issue.

stale[bot] commented 8 months ago

This issue has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed if no further activity occurs within the next 3 days. Thank you for your contributions.

tiger071201 commented 8 months ago

try sending the video as document file

HBiSoft commented 8 months ago

I think it is a video codec issue. WhatsApp probably does not support the codec. There is unfortunately nothing I can do about this. You will either have to select another codec, or you have to convert the video to a codec WhatsApp supports.