调用videoView.start()时如何保持音乐播放?

时间:2015-06-02 07:17:17

标签: android video

我在Android应用中使用VideoView来显示视频。

如果其他应用在后台播放音乐,则调用videoview.start()会停止其他应用在后台播放音乐。

有没有办法确保后台的任何音乐会在调用视频view.start()的同时继续播放? (它没有音频)

谢谢!

1 个答案:

答案 0 :(得分:0)

我也处于相同的场景中:我的要求是,我需要在不影响背景音乐的情况下播放启动视频。我的Splash视频没有任何音频。因此,请创建一个自定义视频视图,并在openVideo()下面的代码行中注释:

//  AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
//  am.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);

现在我的视频视图XML是:

<com.videosample.CustomVideoView
     android:id="@+id/vv_splash_video"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:layout_marginBottom="@dimen/activity_horizontal_margin"
     android:layout_marginLeft="@dimen/activity_horizontal_margin"
     android:layout_marginRight="@dimen/app_common_five_dp_padding"
     android:layout_marginTop="@dimen/activity_horizontal_margin"
     android:visibility="visible" />

我在活动中添加了这样的内容:

mVvSplashVideo = (CustomVideoView) findViewById(R.id.vv_splash_video);
mVvSplashVideo.setZOrderOnTop(true);
Uri uri = Uri.parse("android.resource://" +
    getPackageName() + "/" + R.raw.sample_splash_v4_1);
mVvSplashVideo.setVideoURI(uri);
isVideoPlayCompleted=false;
mVvSplashVideo.start();
mVvSplashVideo.setOnCompletionListener(this);

希望这会对你有所帮助。