androidandroid-viewandroid-videoviewandroid-video-player

Back Button and Black Screen Video


I have a problem in my application . My problem is that Main Class has a VideoView and when I went to other class and return the main class , I see a black screen instead of video .

How can I solve it ?

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        VideoView videoView = (VideoView) findViewById(R.id.videoid);
        Uri adres = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.arkaplan);
        videoView.setVideoURI(adres);
        videoView.requestFocus();
        videoView.start();
        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mp.setLooping(true);
            }
        });

Solution

  • You might want to start the video on onResume() of Activity, instead you having started on onCreate(). There are other things that you have to handle if you start on onResume. But as far I can see from your code, starting a video on Create and moving to other Activity (without finishing) and come back to activity again will call onResume().