简体   繁体   English

如何设置视频的持续时间 - android

[英]How to set duration to a video - android

I am trying to save a 10sec long mp4 file in the gallery (the goal is to upload the vid to facebook).我正在尝试在画廊中保存一个 10 秒长的 mp4 文件(目标是将视频上传到 facebook)。 The log says to me that the file duration is 10sec long - as he should be, but when I'm trying to upload it to Facebook (manually), it appears like the video is 0sec long and I can't upload it.日志告诉我文件持续时间为 10 秒 - 他应该是这样,但是当我尝试将其上传到 Facebook(手动)时,视频似乎为 0 秒长,我无法上传。 (if I'm watching the video on the phone - its works normally, just when I trying to upload it t FB its happens) (如果我正在手机上观看视频 - 它可以正常工作,就在我尝试上传它 t FB 时它发生了)

private void addVideoGallery( File file ) {
    ContentValues values = new ContentValues();
    values.put(MediaStore.Video.VideoColumns.DURATION,10000);
    values.put(MediaStore.Video.Media.DATA, file.getAbsolutePath());
    values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
    Log.d("dur",""+values.getAsLong(MediaStore.Video.VideoColumns.DURATION));
    getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
}

I just want to know if I'm setting the duration right (the actual duration is fixed on 10sec), or I should change/update anything?我只想知道我是否设置了正确的持续时间(实际持续时间固定为 10 秒),或者我应该更改/更新什么?

I've found the solution, i just used the MediaScanner like this:我找到了解决方案,我只是像这样使用了 MediaScanner:

    Intent intent =
      new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

For further information: http://www.grokkingandroid.com/adding-files-to-androids-media-library-using-the-mediascanner/更多信息: http : //www.grokkingandroid.com/adding-files-to-androids-media-library-using-the-mediascanner/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM