I'm using here imageView , when i click on it should show me a video in (linear10) this video is about 4 sec , i need a code that when i click again on the imageView the video should start playing again , every time i clicked on the imageView i need it to start the video from the beginning
this is the code im using to play the video:
imageview1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
n++;
linear1.setVisibility(View.VISIBLE);
if (n == 1) {
final VideoView vd = new VideoView(MainActivity.this); vd.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); linear1.addView(vd);
vd.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.mercury));
vd.requestFocus();
vd.start();
i tried to add this code , but this will loop the video !!! :
vd.setOnCompletionListener(new android.media.MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(android.media.MediaPlayer arg0) {
vd.start();
}
});
i want when i clicked on the imageview the video starts playing, then if i clicked again it will start again from the beginning.
i found the solution guys , ty for help someone called jeff has solve it for me (thanks jeff)
the soulution :
put this code under onCreate:
and this code under imageview1 :