如何录制在媒体播放器中播放的当前直播视频流

时间:2014-07-04 08:10:48

标签: android video-streaming

我搜索了很多内容并且没有取得任何成功。我甚至没有单点可以开始。我正在使用VideoView从网址播放视频,成功播放视频,同时我想录制当前正在播放的视频。例如:http://ip/streamname/playlist.m3u8是网址,我成功观看,但我需要记录特定的流并保存,以便我以后可以观看。请建议我解决方案

1 个答案:

答案 0 :(得分:2)

尝试使用此代码从您的网址下载视频,并记住服务器必须支持从特定字节偏移下载

        private final int TIMEOUT_CONNECTION = 5000;//5sec
        private final int TIMEOUT_SOCKET = 30000;//30sec
        URL url = new URL("Video URL");
      //  long startTime = System.currentTimeMillis();
       // Log.i(TAG, "image download beginning: "+imageURL);

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

        //this timeout affects how long it takes for the app to realize there's a //connection problem
        ucon.setReadTimeout(TIMEOUT_CONNECTION);
        ucon.setConnectTimeout(TIMEOUT_SOCKET);


        //Define InputStreams to read from the URLConnection.
        // uses 3KB download buffer
        InputStream is = ucon.getInputStream();
        BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
        FileOutputStream outStream = new FileOutputStream(file);
        byte[] buff = new byte[5 * 1024];

        //Read bytes (and store them) until there is nothing more to read(-1)
        int len;
        while ((len = inStream.read(buff)) != -1)
        {
            outStream.write(buff,0,len);
        }

        //clean up
        outStream.flush();
        outStream.close();
        inStream.close();

        Log.i(TAG, "download completed in "
                + ((System.currentTimeMillis() - startTime) / 1000)
                + " sec");5
相关问题