I created a video image with a standard one media controlleron it. I was able to play the video by calling method start()in setOnPreparedListener, so the video will automatically play when it finishes preparing it.
However, what I want to do is to backup the video ( NOT automatically played), so the user needs to click / click / tap the video to start the video.
I did some Google search, and I also tried setOnTouchListeneron my video ad and called a method start(). But the result is unexpected (and confusing), a pop-up dialog box appears and says "Video cannot play . "
This is the full code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
txtTitle = (TextView)findViewById(R.id.txtTitle);
player = (VideoView)findViewById(R.id.player);
Bundle video = getIntent().getExtras();
if(video != null)
{
id = video.getString("id");
title = video.getString("title");
rtsp = video.getString("rtsp");
}
txtTitle.setText(title);
pDialog = new ProgressDialog(this);
pDialog.setTitle("Please Wait...");
pDialog.setMessage("Buffering...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
try {
MediaController mediacontroller = new MediaController(this);
mediacontroller.setAnchorView(player);
Uri uri = Uri.parse(rtsp);
player.setMediaController(mediacontroller);
player.setVideoURI(uri);
player.setBackgroundColor(Color.WHITE);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
player.requestFocus();
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
pDialog.dismiss();
player.setBackgroundColor(Color.TRANSPARENT);
}
});
player.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
player.start();
return false;
}
});
}
I was confused because it could be reproduced when I put the method start()in setOnPreparedListener, but could not when I put it in setOnTouchListener.
I don't know if this is related to the problem or not, but im buffering youtube video (RTSP link) on my video ad.
Any help is appreciated, thanks.