I have small but very annoying problem with VideoView in my app. Video is played based on a light sensor value. So I have got defined:
public void onSensorChanged(SensorEvent sensorEvent) {
lightInfo = (TextView)findViewById(R.id.lightInfo);
float light = sensorEvent.values[0];
String fl = Float.toString(light);
lightInfo.setText(fl);
if(light<=60.0f)
{
playOpera = true;
Integer pos3 = position;
Toast.makeText(SensorMobCVActivity.this, "play1-sensor: "+pos3.toString(), 1000).show();
playVideo();
}
else
{
playOpera = false;
if(videoView.getCurrentPosition()>0)
{
position = videoView.getCurrentPosition();
}
Integer pos = position;
Toast.makeText(SensorMobCVActivity.this, "stop1-sensor: "+pos.toString(), 1000).show();
videoView.stopPlayback();
Toast.makeText(SensorMobCVActivity.this, "turn off the light", 1000).show();
}
}
And the playVideo function:
protected void playVideo() {
videoView.setVideoURI(video);
if (position<=videoView.getDuration())
{
position = 0;
}
videoView.seekTo(position);
Integer pos4 = position;
Toast.makeText(SensorMobCVActivity.this, "play2-sensor: "+pos4.toString(), 1000).show();
Toast.makeText(SensorMobCVActivity.this, "Play", 1000).show();
videoView.start();
}
What I want and what I can't get is to seek to the correct position of movie in playVideo. I've tried to put it before and after the videoView.start() and nothing works. each time it starts from the beginning however play1 and play2 shows correct values.
So please tell me what is still wrong in it? It doesn`t work even on static values.
Thank you in advance.