Goofy
Goofy

Reputation: 6128

Delay in playing video file from Input Stream

I am playing the video file from input stream below is my method:

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

But on click of button there is a delay of 3 to 4 seconds to play the video file, why so can any one please help me out?

Upvotes: 2

Views: 2527

Answers (1)

WSS
WSS

Reputation: 513

This delay is due to writing data to temporary file.Instead you can use ParcelFileDescriptor to avoid writing to a temporary file.You can use link(http://www.mattakis.com/blog/kisg/20090708/broadcasting-video-with-android-without-writing-to-the-file-system) as reference.

Upvotes: 2

Related Questions