8

it seems that the videoView supports only a few methods for playing video , but none of them susports the most generic form of playing, which is quite odd (since i thought that all other methods use it).

my question: how can i set the videoView to play an inputStream (any kind of inputStream, even my own customized one) ?

is it possible without actually copying the data to a file and then play it or having some sort of trick to "pipe" the data through ?

i think the same thing is missing for audio, but i'm not sure about it.

android developer
  • 114,585
  • 152
  • 739
  • 1,270

1 Answers1

-1

just try this :

public static String getDataSource(InputStream inputStream) throws IOException {
        if (!URLUtil.isNetworkUrl(path)) {
            return path;
       } else {
           URL url = new URL(path);
           URLConnection cn = url.openConnection();
           cn.connect();
            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;
        }
    }
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • 1
    your code works by reading the entire video and writing it to a file. it should work, but what i wish is live streaming. i've even written about it: "is it possible without actually copying the data to a file and then play it or having some sort of trick to "pipe" the data through ?" – android developer Jul 20 '13 at 15:29
  • maybe it's possible to open a new thread that will write to the file, while we set the videoView read from the file using the normal thread? – android developer Jul 20 '13 at 21:00