2013-07-20 54 views
2

我打从下面输入流的视频文件是我的方法:延迟从输入流播放视频文件

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; 
      } 

但在按一下按钮有一个delay of 3 to 4 seconds播放视频文件,为什么这么能任何人请帮助我?

回答

2

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

+0

可以请你帮我修改我的代码,因为我没有得到你的代码 – Goofy

+0

你从哪里得到你的输入流? – WSS

+0

我有一个自定义数据文件夹,从那里我得到输入流 – Goofy