Android 从输入流播放视频文件时出现延迟
我正在播放输入流中的视频文件,以下是我的方法:Android 从输入流播放视频文件时出现延迟,android,delay,android-videoview,playing,Android,Delay,Android Videoview,Playing,我正在播放输入流中的视频文件,以下是我的方法: public static String getDataSource(InputStream inputStream) throws IOException { InputStream stream = inputStream; if (stream == null) throw new RuntimeException("stream is null");
public static String getDataSource(InputStream inputStream) throws IOException {
InputStream stream = inputStream;
if (stream == null)
throw new RuntimeException("stream is null");
File temp = File.createTempFile("mediaplayertmp", "dat");
temp.deleteOnExit();
String tempPath = temp.getAbsolutePath();
FileOutputStream out = new FileOutputStream(temp);
byte buf[] = new byte[128];
do {
int numread = stream.read(buf);
if (numread <= 0)
break;
out.write(buf, 0, numread);
} while (true);
try {
stream.close();
out.close();
} catch (IOException ex) {
// Log.e(TAG, "error: " + ex.getMessage(), ex);
}
return tempPath;
}
公共静态字符串getDataSource(InputStream InputStream)引发IOException{
InputStream=InputStream;
if(流==null)
抛出新的RuntimeException(“流为null”);
File temp=File.createTempFile(“mediaplayertmp”、“dat”);
temp.deleteOnExit();
字符串tempPath=temp.getAbsolutePath();
FileOutputStream out=新的FileOutputStream(临时);
字节buf[]=新字节[128];
做{
int numread=stream.read(buf);
if(numread此延迟是由于将数据写入临时文件造成的。相反,您可以使用ParcelFileDescriptor避免写入临时文件。您可以使用link()作为参考。我没有收到您的代码,您能帮我修改代码吗?您从哪里获得inputstream?我有一个自定义数据文件夹,从中可以获得输入流