2015-10-28 53 views
0

我正在創建一個Android應用程序,它在​​上運行mediaplayer,並從互聯網上流式傳輸視頻。現在,我想將相同的流視頻錄製到.mp4文件(或以任何格式)到SD卡。我該怎麼做?從運行mediaplayer的紋理視頻錄製視頻

我不能使用surfaceview而不是​​。請幫幫我。

+0

SurfaceView和TextureView在哪裏輸出變。從*那裏捕捉視頻*是漫長的。您想在視頻流到達時抓取視頻流。 – fadden

+0

@fadden我該怎麼做?你能解釋一下嗎? –

回答

0

我有一個解決方案。如果服務器支持下載,請使用以下代碼。

   private final int TIMEOUT_CONNECTION = 5000; //5sec 
       private final int TIMEOUT_SOCKET = 30000; //30sec 
       private final int BUFFER_SIZE = 1024 * 5; // 5MB 


       try { 
        URL url = new URL("http://...."); 

        //Open a connection to that URL. 
        URLConnection ucon = url.openConnection(); 
        ucon.setReadTimeout(TIMEOUT_CONNECTION); 
        ucon.setConnectTimeout(TIMEOUT_SOCKET); 

        // Define InputStreams to read from the URLConnection. 
        // uses 5KB download buffer 
        InputStream is = ucon.getInputStream(); 
        BufferedInputStream in = new BufferedInputStream(is, BUFFER_SIZE); 
        FileOutputStream out = new FileOutputStream(file); 
        byte[] buff = new byte[BUFFER_SIZE]; 

        int len = 0; 
        while ((len = in.read(buff)) != -1) 
        { 
         out.write(buff,0,len); 
        } 
       } catch (IOException ioe) { 
        // Handle the error 
       } finally { 
        if(in != null) { 
         try { 
          in.close(); 
         } catch (Exception e) { 
          // Nothing you can do 
         } 
        } 
        if(out != null) { 
         try { 
          out.flush(); 
          out.close(); 
         } catch (Exception e) { 
          // Nothing you can do 
         } 
        } 
       } 

將help.thanks

+0

這段代碼是否斷言,會有兩個數據流供下載數據和其他媒體播放器使用? –