0
我想在視頻到達當前時間時在TextView中顯示文本。我試過這段代碼:視頻到達當前時間時在TextView中顯示文本Android
public class VideoActivity extends Activity {
private static final String MY_AD_UNIT_ID = null;
protected static final String TAG = null;
private AdView adView;
int waktu;
Button btncek;
private MediaController controller = null;
TextView textView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videoplayer);
Bundle bundle = getIntent().getExtras();
String urlbarus = getIntent().getStringExtra("urlbaru");
final VideoView videoView = (VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(urlbarus);
MediaController.MediaPlayerControl mcEvents = new MediaController.MediaPlayerControl() {
public void start() {
videoView.start();
}
public void seekTo(int pos) {
videoView.seekTo(pos);
}
public void pause() {
videoView.pause();
}
public boolean isPlaying() {
return videoView.isPlaying();
}
public int getDuration() {
return videoView.getDuration();
}
public int getCurrentPosition() {
return videoView.getCurrentPosition();
}
public boolean canSeekForward() {
return true;
}
public boolean canSeekBackward() {
return true;
}
public boolean canPause() {
return true;
}
@Override
public int getBufferPercentage() {
// TODO Auto-generated method stub
return 0;
}
};
controller = new MediaController(this);
controller.setMediaPlayer(mcEvents);
controller.setAnchorView(findViewById(R.id.wrapper));
videoView.start();
if(mcEvents.getCurrentPosition()>=10000){
textView2.setText("kebaca");
}
@Override
public boolean onTouchEvent(MotionEvent event) {
//the MediaController will hide after 3 seconds - tap the screen to make it appear again
controller.show();
return false;
}
這是用於顯示文本代碼:
if(mcEvents.getCurrentPosition()>=10000){
textView2.setText("kebaca");
}
我已經試過的代碼,但沒有任何反應(textview2不顯示文本)
誰能幫我?
這使得力閉合,登錄貓說:致命異常:主要顯示java.lang.NullPointerException – Redturbo
OWH,問題是我忘了申報findviewbyid爲TextView的,後我宣佈它,所有的工作.. – Redturbo
再次有一個問題,代碼是不是真的有用,當我改爲mcEvents.getCurrentPosition()> 10000(我使用if)時,文本顯示從第一次活動啓動(適當的動作是10000毫秒後,文本顯示).. – Redturbo