mediacodec mediaRecoder

If the high level interfaces (MediaPlayer, MediaRecorder) can do what you want (play back video from a format that the system supports to the display, or record video from the camera into a file), you should probably just use them, it will be much much simpler.

如果高阶层的接口(MediaPlayer, MediaRecoder)可以做你想做的(播放某种系统支持播放格式的视频,或者在相机录制视频保存到文件中)你可以只用他们,会更简单。

If you want to do something more custom, when you notice that the part of the chain that you want to modify is hidden inside the high level classes, you'll want to move on to the lower level ones. E.g. for MediaExtractor; if you only want to extract packets of data from a file but not decode and display/play them back them immediately, you'll want to use MediaExtractor. If you want to receive packets from some other source that the system itself doesn't support, you'll want to use MediaCodec without MediaExtractor. Likewise, if you want to record something else than the camera, or write the output somewhere else than to a file that MediaRecorder supports, you'll want to use MediaCodec directly instead of MediaRecorder.

如果你想做某些更定制化的,当你注意到你想修改的部分链条在隐藏在高层的类中,你会想把他们转换成低级别的。例如MediaExtractor;

如果你只想提取文件中的数据包但是不解码或者立即播放,你可以用MediaExtractor。

如果你想从其他系统不支持的来源获取包,你可以用MediaCodec而不是MediaExtractor。

同样的,如果你想不用相机录制东西,或者在不是MediaRecorder支持的文件里写输出,你可以用MediaCodec而不是MediaRecoder。

Also note that the high level classes also improve and get more flexible with newer API versions, allowing you to do things that previously required you to manually use the lower level classes. E.g. in Android 5.0, MediaRecorder got the ability to record from a custom Surface, allowing you to record a video of something you render yourself, not just the camera. This was previously possible since 4.3 by using the lower level classes.

并且注意高层次的类也会随着API版本的更新提升而变得更加灵活,从而可以做一些之前需要手动调用低阶层类的事情。例如在Android5.0中,MediaRecorder可以从自定义的Surface录制,可以录制一些不只是相机而是你自己渲染的视频。这之前只有4.3版本调用低层类来实现。

你可能感兴趣的:(android)