【问题标题】:trying to write a code that can compress a video in small size using yovenny/VideoCompress尝试使用 yovenny/VideoCompress 编写可以压缩小尺寸视频的代码
【发布时间】:2019-10-05 08:24:05
【问题描述】:

自从我尝试编写一个可以将视频压缩为 WhatsApp 等小尺寸视频文件的活动以来,已经有两天了。我已经尝试了我在互联网上找到的所有解决方案,但这些工作人员中没有一个可能是我目前以错误的方式使用它们我在https://github.com/yovenny/VideoCompress 中有一个解决方案,所以我尝试使用它仍然我得到了一些错误.错误说

   java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.nanb.alpha-2/base.apk"],nativeLibraryDirectories=[/data/app/com.nanb.alpha-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libcompress.so"

如果您有其他解决方案,请与我分享并告诉我如何在我的应用程序中实施该解决方案。代码如下。

 public class videocompress extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
    return MediaController.getInstance().convertVideo(params[0],params[1]);
}
@Override
protected void onPostExecute(Boolean compressed) {
    super.onPostExecute(compressed);
    if(compressed){
        Log.d("video compress","Compression successfully!");
    }
}

}

【问题讨论】:

    标签: java android compression


    【解决方案1】:

    使用SiliCompressor

    下面是一些示例代码:

    视频压缩类

    class VideoCompressAsyncTask extends AsyncTask<String, String, String> {
    
    Context mContext;
    String thumbnail;
    
    public VideoCompressAsyncTask(Context context, String thumbnail){
    mContext = context;
    this.thumbnail = thumbnail;
    }
    
    @Override
    protected void onPreExecute() {
    super.onPreExecute();
    pd.setMessage("Uploading Video...");
    pd.show();
    
    }
    
    @Override
    protected String doInBackground(String... paths) {
    String filePath = null;
    try {
    
    filePath = SiliCompressor.with(mContext).compressVideo(paths[0], paths[1]);
    
    } catch (URISyntaxException e) {
    e.printStackTrace();
    }
    return filePath;
    
    }
    
    
    @Override
    protected void onPostExecute(String compressedFilePath) {
    super.onPostExecute(compressedFilePath);
    UploadMedia(compressedFilePath, thumbnail,"video");
    Log.i("Silicompressor", "Path: "+compressedFilePath);
    }
    }
    

    onActivityResult 中你调用这个类

    if(requestCode == SELECT_VIDEO && resultCode == RESULT_OK)
    {
    Uri uri = data.getData();
    String[] projection = { MediaStore.Video.Media.DATA };
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
    if(cursor!=null) {
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();
    File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + getPackageName() + "/media/videos");
    if (f.mkdirs() || f.isDirectory())
    //compress and output new video specs
    new VideoCompressAsyncTask(this,getThumbnailPathForLocalFile(this,uri)).execute(cursor.getString(column_index), f.getPath());
    cursor.close();
    }else
    Toast.makeText(ChatScreen.this, "No Video Found", Toast.LENGTH_SHORT).show();
    }
    

    您也可以通过此方法获取视频缩略图

    public static String getThumbnailPathForLocalFile(ChatScreen context, Uri fileUri ) {
        long fileId = getFileId(context, fileUri);
        Log.e("ID",fileId+"");
        MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),
                fileId, MediaStore.Video.Thumbnails.MICRO_KIND, null);
        Cursor thumbCursor = null;
        try {
            thumbCursor = context.managedQuery(
                    MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI, thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + " = " + fileId, null, null);
            if (thumbCursor.moveToFirst()) {
                String thumbPath = thumbCursor.getString(thumbCursor
                        .getColumnIndex(MediaStore.Video.Thumbnails.DATA));
                Log.e("ThumbPath",thumbPath);
                return thumbPath;
            }
    
        } finally {
        }
        return null;
    }
    

    【讨论】:

    • 感谢您的回答,但 dint 工作没有创建文件并且找不到临时文件方法
    猜你喜欢
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2018-11-09
    • 2014-02-14
    相关资源
    最近更新 更多