android - 从输入流播放视频文件时出现延迟

标签 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");
            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;
          }

但是单击按钮时,播放视频文件会延迟 3 到 4 秒,为什么有人可以帮我解决这个问题吗?

最佳答案

此延迟是由于将数据写入临时文件造成的。您可以使用 ParcelFileDescriptor 来避免写入临时文件。您可以使用链接( http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system ) 作为引用。

关于android - 从输入流播放视频文件时出现延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17761777/

相关文章:

android - 在线为Android应用程序VideoView存储视频

Android MediaPlayer.setVolume(0,0) 没有使视频静音

java - Android camera2 API 内存泄漏

android - PouchDB 未使用 cordova 检测 sqlite 插件

android - Android 上使用 Wifi 的 HttpClient 导致延迟(根据初始请求)

vhdl - 简单 VHDL 电路的意外行为

在 VideoView 中播放视频时,Android 后退按钮不起作用

Android 替代 jtable?

Android - 一个项目中支持多个 SDK?

android - ProgressDialog Box虚拟计时器