3

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.

sebap123
  • 2,541
  • 6
  • 45
  • 81

1 Answers1

-1

try this code, put it on your seekbar progress change
videoPosition = videoView.getCurrentPosition() + yourSeekBarProgress; videoView.seekTo(videoPosition); videoView.start();

Hiren Dabhi
  • 3,693
  • 5
  • 37
  • 59
  • The thing is that I haven't got any seekbar and it is working good without it. The funny thing is that before I put start and seekto into function determined my light sensor everything works fine. – sebap123 Dec 28 '11 at 12:47