2015-06-02 50 views
0

我在Android應用程序中使用VideoView來顯示視頻。如何在調用videoView.start()時保持音樂播放?

如果其他應用程序正在播放的背景音樂,調用videoview.start()在後臺的其他應用程序停止音樂播放。

有沒有一種方法,以確保所有的背景音樂將保持在同一時間與調用視頻view.start()玩? (它沒有音頻)

謝謝!

回答

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

希望這會對你有所幫助。

+0

**我有同樣的問題,** 我想繼續玩其他音樂播放器的音樂app.but當我的應用程序開始播放影片,然後音樂stop.so請分享你的「CustomVideoView」級 – bhoomika

相關問題