Android Google Music app stops when my intro video plays

最后都变了- 提交于 2019-11-28 01:58:42

问题


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 music playing in Google Music App in the background.

Is there a way to make sure any music in the background will keep playing at the same time with my intro video? (it has no audio)

Thank you!


回答1:


Turns out Google Music App and a few other apps will stop their music when any video starts playing.

In order to make sure I'm not interrupting the listening experience for my users I now skip the intro video if I determine that there is music playing in the background.

To do this:

AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

if (am.isMusicActive()) {
    loadApp();   // skip video and go straight to the app
}
else {
    videoView.start();  // play video
}



回答2:


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));
    }
});



回答3:


Taken from openVideo() in VideoView.java

 Intent i = new Intent("com.android.music.musicservicecommand");
 i.putExtra("command", "pause");
 mContext.sendBroadcast(i);


来源:https://stackoverflow.com/questions/8995176/android-google-music-app-stops-when-my-intro-video-plays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!