【问题标题】:Android Google Music app stops when my intro video plays播放我的介绍视频时,Android Google 音乐应用停止
【发布时间】:2019-01-04 19:32:03
【问题描述】:

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

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

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

谢谢!

【问题讨论】:

    标签: android audio android-videoview


    【解决方案1】:

    事实证明,当任何视频开始播放时,Google 音乐应用和其他一些应用都会停止播放音乐。

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

    为此:

    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】:

      使用前面给出的两个答案,这里有一个解决方案,可以在您的视频结束后恢复音乐:

      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】:

      取自VideoView.java中的openVideo()

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

      【讨论】:

      • 这如何回答这个问题?
      猜你喜欢
      • 2013-01-25
      • 1970-01-01
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      • 1970-01-01
      相关资源
      最近更新 更多