- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有从后置摄像头录制视频的服务:
this.mMediaRecorder = new MediaRecorder();
this.mMediaRecorder.setCamera(mCamera);
this.mMediaRecorder.setVideoSource(VideoSource.CAMERA);
this.mMediaRecorder.setOutputFormat(OutputFormat.DEFAULT);
this.mMediaRecorder.setVideoEncoder(VideoEncoder.DEFAULT);
this.mMediaRecorder.setVideoSize(photo_resolution[0], photo_resolution[1]);
this.mParcelFileDescriptor = ParcelFileDescriptor.fromSocket(this.mSocket);
this.mMediaRecorder.setOutputFile(this.mParcelFileDescriptor.getFileDescriptor());
this.mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
this.mMediaRecorder.prepare();
this.mMediaRecorder.start();
视频没有声音。我使用以下代码连接到服务器:
this.mSocket = new Socket();
this.mSocket.connect(new InetSocketAddress(...), 30000);
this.in = new BufferedReader(new InputStreamReader(this.mSocket.getInputStream(), "UTF-8"));
this.out = this.mSocket.getOutputStream();
this.out.write(("some string" + "\n").getBytes("UTF-8"));
this.out.flush();
...
我已经将所有需要的权限添加到 AndroidManifest.xml 中。
问题是视频未广播到服务器。我尝试将 this.mParcelFileDescriptor.getFileDescriptor()
替换为 "/sdcard/video.mp4"
,一切正常 - 视频录制正确。但它不发送到套接字。客户端(在我的应用程序中)没有发生任何事情,但服务器端向我抛出异常java.net.SocketTimeoutException:读取超时
。我在服务器端尝试了此代码:
byte[] bytes = new byte[1024];
int read = mSocket_inputStream.read(bytes, 0, 1024);
System.out.println(read);
调试我从客户端(从我的应用程序)读取的字节数 - 控制台中没有调试任何内容,因为发送了 0 个字节。请帮我解决这个问题。我在谷歌中没有找到解决方案。
最佳答案
文件描述符仅适用于 MediaRecorder 中的本地服务器套接字。
this.mParcelFileDescriptor = ParcelFileDescriptor.fromSocket(this.mSocket);
this.mMediaRecorder.setOutputFile(this.mParcelFileDescriptor.getFileDescriptor();
您可以创建自己的 LocalServerSocket,然后将数据从本地服务器套接字传递到实际服务器套接字
要了解有关本地服务器套接字的更多信息,您可以通过 https://developer.android.com/reference/android/net/LocalServerSocket.html
更有效的方法是使用 MediaCodec API 进行录制,因为它将以字节缓冲区的格式逐帧为您提供数据,并且您可以将该数据发送到服务器。
关于java - mMediaRecorder.setOutputFile(ParcelFileDescriptor.fromSocket(mSocket)) - 没有写入 mSocket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40362154/
我阅读了 Android SDK,发现 MediaRecorder 类可以从相机、音频或其他来源获取输入并进行压缩。通过 setOutputFile 方法,您可以指定要存储数据的位置(文件或 URI)
我正在开发一个 Android 应用程序,它应该能够将视频流式传输到我网络上的本地服务器,而无需将其存储在 SD 卡上。 为此,我在 C# 中创建了一个简单的套接字应用程序,用于监听特定的 IP:PO
我正在我的应用程序中录制音频,但我正在努力处理 MediaRecorder 类 import android.media.MediaRecorder; 问题是代码编译但似乎无法在 API 级别 < 2
本文整理了Java中com.android.build.gradle.tasks.ZipAlign.setOutputFile()方法的一些代码示例,展示了ZipAlign.setOutputFile
我有从后置摄像头录制视频的服务: this.mMediaRecorder = new MediaRecorder(); this.mMediaRecorder.setCamera(mCamera);
我在我的 Android 应用程序中使用 MediaRecorder。我引用了 MediaRecorder 类的 public void setOutputFile (String path) 的在线
我在一个 Android 应用程序项目中使用以下简化配置。 android { compileSdkVersion 20 buildToolsVersion "20.0.0"
我是一名优秀的程序员,十分优秀!