I have successfully played a video using MediaPlayer on TextureView, now I am trying to program so that the video automatically changes after a certain frame is passed. However, after a certain condition is met, I am unable to update the video. It is stuck at the first video(the last frame before the condition is met).
How do I load a new video and start playing once the first video is passed a certain frame? Here is what I have, I use a CountDownTimer for getting the most accurate current time.
public class PreviewVideo extends AppCompatActivity implements TextureView.SurfaceTextureListener {
TextureView textureView;
MediaPlayer videoMedia;
Boolean pastFrame=false;
int currentTime;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview_video);
textureView = (TextureView) findViewById(R.id.previewVideo);
textureView.setSurfaceTextureListener(this);
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
surf=new Surface(surface);
videoMedia=new MediaPlayer();
videoMedia.setSurface(surf);
try{
if (!pastFrame){
videoMedia.setDataSource(this,firstUri);
}
else {
videoMedia.setDataSource(this,secondUri);
}
videoMedia.prepare();
playListeners();
} catch(IOException e){e.printStackTrace(); }
}
private void playListeners() {
count=new CountDownTimer(videoMedia.getDuration()*10, 1){
@Override
public void onTick(long l)
{
currentTime=videoMedia.getCurrentPosition();
if (currentTime>=setFrame && pastFrame==false){
textureView.setSurfaceTextureListener(this);//Do I call this again??
pastFrame=true;
}
@Override
public void onFinish(){
}
}.start();
}
}