我用谷歌搜索了很多,但没有发现任何成功。甚至没有一个可以让我启动的点。我正在使用 VideoView 播放来自 url 的视频,成功播放视频,同时我想录制当前播放的视频。例如: http://ip/streamname/playlist.m3u8
是网址,我成功观看了它,但我需要记录特定的流并保存它,以便我以后可以观看。请给我建议解决方案
最佳答案
尝试使用此代码从您的网址下载视频,记住一件事:服务器必须支持从特定字节偏移量下载
private final int TIMEOUT_CONNECTION = 5000;//5sec
private final int TIMEOUT_SOCKET = 30000;//30sec
URL url = new URL("Video URL");
// long startTime = System.currentTimeMillis();
// Log.i(TAG, "image download beginning: "+imageURL);
//Open a connection to that URL.
URLConnection ucon = url.openConnection();
//this timeout affects how long it takes for the app to realize there's a //connection problem
ucon.setReadTimeout(TIMEOUT_CONNECTION);
ucon.setConnectTimeout(TIMEOUT_SOCKET);
//Define InputStreams to read from the URLConnection.
// uses 3KB download buffer
InputStream is = ucon.getInputStream();
BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
FileOutputStream outStream = new FileOutputStream(file);
byte[] buff = new byte[5 * 1024];
//Read bytes (and store them) until there is nothing more to read(-1)
int len;
while ((len = inStream.read(buff)) != -1)
{
outStream.write(buff,0,len);
}
//clean up
outStream.flush();
outStream.close();
inStream.close();
Log.i(TAG, "download completed in "
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");5
关于android - 如何录制媒体播放器中当前正在播放的实时视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24569604/