I want to play a video in android that I saved in a folder with my resources. I changed it to a byte array and it works successfully using the code below
private String getDataSource() throws IOException { InputStream stream = getAssets().open("famous.3gp"); if (stream == null) throw new RuntimeException("stream is null"); File temp = File.createTempFile("test", "mp4"); temp.deleteOnExit(); String tempPath = temp.getAbsolutePath(); int totalRead = 0; int bytesToRead = 1 * 1024; FileOutputStream out = new FileOutputStream(temp); byte buf[] = new byte[128]; int numread = 0; do { numread = stream.read(buf); totalRead += numread; if (numread <= 0) break; out.write(buf, 0, numread); } while (totalRead<bytesToRead); try { stream.close(); } catch (IOException ex) { Log.e("mini", "error: " + ex.getMessage(), ex); } return tempPath;
and oncreate
videoView.setVideoPath(getDataSource());
But my requirement: I want to play as the first 100 bytes from the array, and when it's finished, do the next 100 bytes, and then another 100 bytes.
android file-io video-streaming videoview
Meeenal
source share