开发者

Media Recorder setMaxFileSize problem

开发者 https://www.devze.com 2023-03-09 21:18 出处:网络
I have a problem trying to set the max file size when recording video.The documentation for recorder.setMaxFileSize(long filesize_in_bytes) says long variable type for the argument. I have a method th

I have a problem trying to set the max file size when recording video. The documentation for recorder.setMaxFileSize(long filesize_in_bytes) says long variable type for the argument. I have a method that returns the free space in long value. When I try to set this long variable as the argument it fails every time.

Free Space Method

public long freeSpace(){
StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long free = (long)stat.getBlockSize() *(long)stat.getBlockCount();
Log.w("FREESPACE METHOD", "Free space on SD card: "+free);
return free;
}

Excerpt from the media recorder method

long spaceFree = freeSpace();
recorder.setblahblah
recorder.setMaxFileSize(spaceFree);  //Fails right here.

Logcat

05-31 00:30:28.201: ERROR/AndroidRuntime(176开发者_开发百科97): Caused by: java.lang.RuntimeException: setMaxFileSize failed.

However if is do this recorder.setMaxFileSize(5000000L); it works.

What obvious thing am I missing?


Use getAvailableBlocks() instead of getBlockCount(). Looks like you're getting the total size of the SD Card, not the free space.


I found the answer. I forgot that the FAT file system has a maximum file size of 4 GB. So if you use a large card like so many users have now, there may be over 4GB of free space. This is a file system limitation.

There is also another stack overflow answer on this here

0

精彩评论

暂无评论...
验证码 换一张
取 消