For the last 18 Months I have been building simple apps in android studio and I am really stuck trying to work this out so any help would be great
So far my app works great, open the app on the first activity and press the play button and the 2nd activity opens and plays the video, at the end of the video it returns back to the first activity, but I am trying to exit the app
guessing I should be able to add something like
public void onCompletion(MediaPlayer player) {
onStop();
onDestroy();
}
public class PlayVideo extends Activity {
boolean videoPlayed ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play_video);
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_FULLSCREEN |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
videoPlayed = true;
playvideo();
FinishVideo();
}
public void playvideo() {
VideoView videoview = (VideoView) findViewById(R.id.videoview);
Uri uri = Uri.parse("android.resource://" + getPackageName()
+ "/"+ R.raw.sound_2);
videoview.setVideoURI(uri);
videoview.start();
}
public void FinishVideo() {
VideoView videoView = (VideoView) findViewById(R.id.videoview);
videoView.setOnCompletionListener
(newMediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer player) {
//Log.i("VideoView", "onCompletion()");
//Intent intent = new Intent
(PlayVideo.this,MainActivity.class);
//startActivity(intent);
System.exit(0);
}
});
}
}
----------------------------------------------------------------------------
<RelativeLayout xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PlayVideo">
<VideoView
android:id="@+id/videoview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>