无法使VideoView寻求特定的位置 - Android

时间:2011-12-28 11:45:47

标签: java android

我的应用中的VideoView有一个很小但很烦人的问题。视频基于光传感器值播放。所以我已经定义了:

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();
    }
}

播放视频功能:

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();
}

我想要的和我无法获得的是在playVideo中寻找正确的电影位置。我试图在videoView.start()之前和之后放置它并且没有任何效果。每次从头开始,然而play1和play2显示正确的值。

那么请告诉我它还有什么问题?它甚至对静态值也不起作用。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试此代码,将其放在您的搜索栏进度更改上 videoPosition = videoView.getCurrentPosition() + yourSeekBarProgress; videoView.seekTo(videoPosition); videoView.start();