用于在firebase存储空间中上传的视频压缩

时间:2017-06-30 06:56:11

标签: android video compression media-queries firebase-storage

我正在尝试捕获视频并将其上传到firebase存储中。该视频上传得很好,但上传时间过长。我想压缩它,然后上传它。有什么建议?我尝试过使用“Silicompressor”lib,但它也无法使用。因此,我没有使用任何MediaRecorder类,我猜我无法使用android视频压缩sdk。我读过关于使用FFMPEG的内容,但是我很难理解,因为我是新手。请帮忙。如果有人知道一些简单的方法,请指导我。提前致谢。 在我的gradel文件中依赖于硅压缩机 - 编译'com.iceteck.silicompressorr:silicompressor:2.0' 我没有得到什么放在destinationUriString以及如何继续。 `

private void startRecording() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == Activity.RESULT_OK) {
        filePath = data.getData();
        file= Environment.getExternalStorageDirectory().getAbsolutePath();
        file+= "/Videos.mp4";

    }
}

public void upLoadVideo() {
    //mProgress.setMessage("Your file's uploading... ");
   // mProgress.show();
    String uuid = UUID.randomUUID().toString();
String filePath = SiliCompressor.with(this.getApplication()).compressVideo(file.toString(), destinationUriString);
        StorageReference riversRef = mStorageRef.child(mUserId).child("video" + uuid + ".flv");

    riversRef.putFile(filePath).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
           //  mProgress.dismiss();
            Uri dUrl = taskSnapshot.getDownloadUrl();
            downloadUri = dUrl.toString();

            Toast.makeText(getApplicationContext(), "Done..", Toast.LENGTH_SHORT).show();
            alert();
        }
    });

}


public void alert() {


    AlertDialog alertDialog = new AlertDialog.Builder(
            VideoFragment.this).create();

    {
        // Setting Dialog Title
        alertDialog.setTitle("Alert Dialog");

        // Setting Dialog Message
        alertDialog.setMessage("Any requirments in mind?");
        alertDialog.setButton(Dialog.BUTTON_POSITIVE, "YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                uploadbutton = (Button) findViewById(R.id.uploadbutton);
                uploadbutton.setEnabled(false);
                uploadbuttonR = (Button) findViewById(R.id.button4);
                uploadbuttonR.setEnabled(true);
                reqButton = (Button) findViewById(R.id.reqButton);
                reqButton.setEnabled(true);
                // Write your code here to invoke YES event
                Toast.makeText(getApplicationContext(), "To add requirments Click Requiments", Toast.LENGTH_SHORT).show();
            }
        });

        // Setting Negative "NO" Button
        alertDialog.setButton(Dialog.BUTTON_NEGATIVE, "NO", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //r= "yes";
                Toast.makeText(getApplicationContext(), "OK!", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                downloadUriR="NULL";
                Upload user = new Upload("1001p","energysaving", downloadUri,downloadUriR);
                dataref.child(mUserId).push().setValue(user);
               // sendEmail();
                Intent i = new Intent(getApplicationContext(), ThanksActivity.class);
                startActivity(i);
            }
        });

        alertDialog.show();

    }
}

0 个答案:

没有答案