Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void bufferVideoUrl(){
- new Thread(){
- @Override
- public void run(){
- try {
- URL url = new URL("http://media-br-am.crackle.com/1/h/96/m21lf_480p.mp4");
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- httpURLConnection.connect();
- InputStream inputStream = httpURLConnection.getInputStream();
- //inputStream.read();
- int line;
- byte[] bytes = new byte[32 * 1024];
- File file = new File("Filme2.mp4");
- if(!file.exists())
- file.createNewFile();
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
- int loopCount = 0;
- boolean playVideo = false;
- while ((line = inputStream.read(bytes)) != -1){
- System.out.println("Bufferizando");
- bufferedOutputStream.write(bytes,0, line);
- bufferedOutputStream.flush();
- loopCount += line;
- if(loopCount >= 12000 && !playVideo) {
- //System.out.println("Exibindo Video"+file.toString());
- showVideo(file.toString());
- playVideo = true;
- }
- }
- bufferedOutputStream.close();
- showVideo(file.toString());
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement