我需要对在 android (MediaPlayer) 上播放的一个视频执行过滤器,这个过滤器只会将背景变为透明,但我如何读取要处理的字节?因为 android 似乎不运行 alpha 通道电影 :(
我需要这个来将视频放在覆盖相机预览(AR)的全屏中。这就是为什么我需要透明的电影背景。
我的想法是将 MediaPlayer 帧数据(位图数据)发送到 NDK 进程,然后将处理后的位图返回到表面视图。
PS:Android API8,目标2.2+
按照下面我的代码:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.SurfaceView;
public class MovieSurfaceView extends SurfaceView {
public MovieSurfaceView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
}
}
/** The main activity for the ImageTargets sample. */
public class ImageTargets extends Activity implements SurfaceHolder.Callback
{
private MovieSurfaceView mPreview;
private MediaPlayer mMediaPlayer;
private SurfaceHolder holder;
private String videoPath = "/LAST.3g2";
protected void onCreate(Bundle savedInstanceState)
{
DebugLog.LOGD("ImageTargets::onCreate");
super.onCreate(savedInstanceState);
initApplicationAR();
}
private void initApplicationAR()
{
mPreview = new MovieSurfaceView(this);
addContentView(mPreview, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
// holder = mGlView.getHolder();
holder = mPreview.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(this);
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDisplay(holder);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
}
);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
mp.reset();
}
}
);
iniPlayer();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0)
{
// TODO Auto-generated method stub
}
}