2014-09-05 15 views
6

Desidero scaricare e riprodurre file video durante il download. Dal momento che VideoView non aiuta questo argomento ho deciso di lavorare con nanoHTTPd per creare uno pseudo server HTTP e nel mio server provare a scaricare il file video e riprodurlo in seguito, ma il mio problema è:come eseguire lo streaming di video da Internet tramite nanoHTTPd a VideoView

1-Come posso scaricare a livello scaricabile parte per videoview e scarica le parti rimanenti?

seguito è la mia fonte:

public class VideoStreamingServer extends NanoHTTPD { 

     public VideoStreamingServer() { 
      // by default listening on port 8080 
      super(8080); 
     } 

     @Override 
     public Response serve(String URI, Method method, 
           Map header, Map parameters, Map files) { 

      FileInputStream fis = null; 
      try { 
//    fis = new FileInputStream("/mnt/sdcard/p/1.mp4"); 

       File bufferFile = File.createTempFile("test", "mp4"); 

       BufferedOutputStream bufferOS = new BufferedOutputStream(
         new FileOutputStream(bufferFile)); 

       HttpClient client = new DefaultHttpClient(); 
       HttpGet request = new HttpGet("http://www.example.net/dl/1.mp4"); 
       HttpResponse response = client.execute(request); 
       Header[] headers = response.getAllHeaders(); 
       Log.e("Internet buffer", "connected to server"); 

       BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent(), 2048); 


       byte[] buffer = new byte[16384]; 
       int numRead; 
       boolean started = false; 
       while ((numRead = bis.read(buffer)) != -1) { 

        bufferOS.write(buffer, 0, numRead); 
        bufferOS.flush(); 
        totalRead += numRead; 
        if (totalRead > 120000 && !started) { 
          //problem starts here 
          //How can I flush the buffer to VideoView? 


        } 

       } 


      } catch (FileNotFoundException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 


      return new NanoHTTPD.Response(Response.Status.OK, "video/mp4", fis); 
     } 
    } 
+0

un'occhiata qui, è una risposta nel mezzo della pagina: http: // StackOverflow. it/questions/9987042/videoview-onresume-loses-buffered-portion-of-the-video – CristiC777

risposta

-1

trovato un modo, si può leggere di più qui: http://www.vahidhashemi.com/?p=120

+2

Non mi piace che sia una risposta di solo collegamento, ma è utile (e non ancora morto). Sarebbe meglio se tu potessi spiegare l'idea generale, quindi rimane qui quando il link muore (alla fine * morirà). Allora lo avrei votato. – Matthieu

Problemi correlati