android - 如何录制媒体播放器中当前正在播放的实时视频流

标签 android video-streaming

我用谷歌搜索了很多,但没有发现任何成功。甚至没有一个可以让我启动的点。我正在使用 VideoView 播放来自 url 的视频,成功播放视频,同时我想录制当前播放的视频。例如: http://ip/streamname/playlist.m3u8 是网址,我成功观看了它,但我需要记录特定的流并保存它,以便我以后可以观看。请给我建议解决方案

最佳答案

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

        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

关于android - 如何录制媒体播放器中当前正在播放的实时视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24569604/

相关文章:

java - 通话录音失败,出现 java.lang.IllegalStateException

java - 杀死应用程序,在 Application 类的 onTrimMemory 方法中

javascript - 将 block 加载到 html5 视频中

angularjs - HTML5 视频无法播放且媒体请求中止

java - 在已经存在的 SharedPreference 值中更改数据类型

java - 安卓+Java :File deletion error

java - 如何知道从动态添加的 View 中单击了哪些切换按钮?

java - 在读取小长度字节时,使用 DataInputStream 读取性能较慢

javascript - 跨源视频可以工作 html5 但不能工作 webgl

javascript - 在 html 中显示 RTSP 流