来自 textureview 运行 mediaplayer 的视频录制

Video recording from a textureview running mediaplayer

我正在创建一个 android 应用程序,它是 运行 在 textureview 上的 mediaplayer,以及来自 Internet 的流式视频。现在,我想将相同的流媒体视频录制到 .mp4 文件(或任何格式)到 SD 卡。我该怎么做?

我不能用 surfaceview 代替 textureview。请帮助我。

我找到了解决办法。如果服务器支持下载使用下面的代码。

                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