I used https://github.com/krazykira/VidEffects
to apply filter on playing video. But I want to change the filter on click of button at runtime without any glitch on playing video.
According to Applying Effects on Video being Played
I should use
mVideoView.init(mMediaPlayer,new filter)
whenever I want to change filter.But there is no effect on playing video
Can someone help me... I am not experienced in using GLSurfaceView.
Here is my java class
public class MainActivity extends Activity {
private static final String TAG = "MediaPlayerSurfaceStubActivity";
protected Resources mResources;
ShaderInterface d = null;
private VideoSurfaceView mVideoView = null;
private MediaPlayer mMediaPlayer = null;
private Button button;
LinearLayout linear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mVideoView = (VideoSurfaceView) findViewById(R.id.mVideoSurfaceView);
linear = (LinearLayout) findViewById(R.id.linear);
button = (Button) findViewById(R.id.effects);
//HERE , on click of following button I want the effect to be applied at runtime.
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.gc();
mVideoView.init(mMediaPlayer, new VignetteEffect(2));
}
});
mResources = getResources();
mMediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor afd = getAssets().openFd("sample.mp4");
mMediaPlayer.setDataSource(afd.getFileDescriptor(),
afd.getStartOffset(), afd.getLength());
} catch (Exception e) {
e.printStackTrace();
}
mVideoView.init(mMediaPlayer,
new SepiaEffect());
}
@Override
protected void onResume() {
super.onResume();
mVideoView.onResume();
}
}
My xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linear"
tools:context="videoeditor.xcs.com.videoeffect.MainActivity">
<com.sherazkhilji.videffect.view.VideoSurfaceView
android:id="@+id/mVideoSurfaceView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="effects"
android:id="@+id/effects"/>
</LinearLayout>
In this Sepia Effect is already set but I want to change that to vignette on button click