当我的介绍视频播放时 Android Google Music 应用停止

发布于 2024-12-28 21:33:56 字数 176 浏览 2 评论 0原文

我在 Android 应用程序中使用 VideoView 来显示介绍动画。

如果 Google 音乐应用程序正在后台播放音乐,则调用 videoview.start() 会停止 Google 音乐应用程序在后台播放音乐。

有没有办法确保背景音乐与我的介绍视频同时播放? (没有声音)

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

给不了的爱 2025-01-04 21:33:56

事实证明,当任何视频开始播放时,谷歌音乐应用程序和其他一些应用程序将停止播放音乐。

为了确保我不会中断用户的聆听体验,如果我确定背景中有音乐播放,我现在会跳过介绍视频。

为此:

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

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

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
}
小矜持 2025-01-04 21:33:56

使用之前给出的两个答案,这是一个在视频结束后恢复音乐的解决方案:

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

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));
    }
});
桜花祭 2025-01-04 21:33:56

取自 VideoView 中的 openVideo() .java

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

Taken from openVideo() in VideoView.java

 Intent i = new Intent("com.android.music.musicservicecommand");
 i.putExtra("command", "pause");
 mContext.sendBroadcast(i);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文