The code you reference isn't a sample, but rather internal test code that exercises a non-public interface. SurfaceMediaSource
could change or disappear in a future release and break your code.
Update:
Android 4.3 (API 18) allows Surface input to MediaCodec
. The EncodeAndMuxTest sample demonstrates recording OpenGL ES frames to a .mp4 file.
The MediaRecorder
class doesn't take Surface input, so in your case you'd need to record the audio separately and then combine it with the new MediaMuxer class.
Update #2: Android 5.0 (API 21) allows Surface input to MediaRecorder, which is often much more convenient than MediaCodec. If you neeed to use MediaCodec, there is an example showing three different ways of recording OpenGL ES output with it in Grafika's "record GL activity".
The MediaProjection class can also be useful for screen recording.