Android Google Music app stops when my intro video plays

前端 未结 3 498
被撕碎了的回忆
被撕碎了的回忆 2020-12-18 13:40

I\'m using a VideoView in my Android app to display the intro animation.

If the Google Music App is playing music in the background, calling videoview.start() stops

3条回答
  •  萌比男神i
    2020-12-18 14:28

    Using both the answers previously given, here is a solution that will resume music after your video ends:

    final boolean music_was_playing = ((AudioManager) getSystemService(Context.AUDIO_SERVICE)).isMusicActive();
    
    VideoView vv_Video = (VideoView) findViewById(R.id.intro_video_view);
    
    // play the intro video
    vv_Video.setOnCompletionListener( new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer m) {
            // resume music if it was playing cause our intro video just paused it temporarily
            if (music_was_playing) {
                Intent i = new Intent("com.android.music.musicservicecommand");
                i.putExtra("command", "play");
                sendBroadcast(i);
            }
    
            // go to main menu
            startActivity(new Intent(IntroActivity.this, MainMenuActivity.class));
        }
    });
    

提交回复
热议问题