【发布时间】:2015-03-05 18:58:26
【问题描述】:
给定一个视频网址(例如:www.example.com/video.mp4),我如何以编程方式保存视频的短片(例如:5 秒,00:00:10 - 00:00:15)在手机上的 Android 应用程序中?
目前,这就是我所拥有的 - 但这会将整个视频从 url 保存到设备。看来我需要使用 MediaExtractor 和 MediaMuxer。
URL url = new URL(http_url_path);
URLConnection ucon = url.openConnection();
// Define InputStreams to read from the URLConnection.
// uses 5KB download buffer
InputStream is = ucon.getInputStream();
BufferedInputStream in = new BufferedInputStream(is, BUFFER_SIZE);
FileOutputStream out = new FileOutputStream(file);
byte[] buff = new byte[BUFFER_SIZE];
int len = 0;
while ((len = in.read(buff)) != -1) {
out.write(buff, 0, len);
}
【问题讨论】:
标签: android video fileoutputstream mediamuxer mediaextractor