Skip to content

Instantly share code, notes, and snippets.

@jacks205
Last active November 2, 2015 21:44
Show Gist options
  • Save jacks205/95a2451ae4f4c8e0fcee to your computer and use it in GitHub Desktop.
Save jacks205/95a2451ae4f4c8e0fcee to your computer and use it in GitHub Desktop.
public static String VIDEO_URL = "https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/gear1/fileSequence0.ts";
private volatile byte[] videoBuffer;
private volatile VideoDownloadListener listener;
private volatile boolean isDownloading;
Runnable downloadVideoRunnable = new Runnable() {
@Override
public void run() {
try{
URL url = new URL(VIDEO_URL);
//Open the stream for the file.
InputStream inputStream = url.openStream();
//For appending incoming bytes
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int read = 0;
while (read != -1){ //While there is more data
//Read in bytes to data buffer
read = inputStream.read();
//Write to output stream
byteArrayOutputStream.write(read);
}
inputStream.close();
//Flush and set buffer.
byteArrayOutputStream.flush();
videoBuffer = byteArrayOutputStream.toByteArray();
byteArrayOutputStream.close();
listener.onVideoDownloaded();
}catch (Exception e){
listener.onVideoDownloadError(e);
}finally {
isDownloading = false;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment