出自:http://www.xdty.org/1548
mAudioManager
=
(AudioManager
) mProxy.
getContext
(
).
getSystemService
(
Context.
AUDIO_SERVICE
)
;
mAudioManager. requestAudioFocus ( null, AudioManager. STREAM_MUSIC,
AudioManager. AUDIOFOCUS_GAIN_TRANSIENT ) ;
mAudioManager. requestAudioFocus ( null, AudioManager. STREAM_MUSIC,
AudioManager. AUDIOFOCUS_GAIN_TRANSIENT ) ;
diff
--git a
/HTML5VideoView.
java b
/HTML5VideoView.
java
index 0e8a5db..3aa36b4 100755
--- a /HTML5VideoView. java
+++ b /HTML5VideoView. java
@@ - 17, 6 + 17, 10 @@
package android.webkit ;
import android.media.MediaPlayer ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ import android.media.AudioManager ;
+ import android.content.Context ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
import android.net.Uri ;
import android.webkit.HTML5VideoViewProxy ;
import java.io.IOException ;
@@ - 62, 6 + 66, 9 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
// player at the same time. We may recreate a new one and abandon the old
// one at transition time.
protected static MediaPlayer mPlayer = null ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ private static AudioManager mAudioManager = null ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
protected static int mCurrentState = - 1 ;
// We need to save such info.
@@ - 89, 6 + 96, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
mTimer. schedule ( new TimeupdateTask (mProxy ), TIMEUPDATE_PERIOD,
TIMEUPDATE_PERIOD ) ;
}
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ mAudioManager = (AudioManager ) mProxy. getContext ( ). getSystemService ( Context. AUDIO_SERVICE ) ;
+ mAudioManager. requestAudioFocus ( null, AudioManager. STREAM_MUSIC,
+ AudioManager. AUDIOFOCUS_GAIN_TRANSIENT ) ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
mPlayer. start ( ) ;
setPlayerBuffering ( false ) ;
}
@@ - 97, 6 + 109, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
public void pause ( ) {
if (isPlaying ( ) ) {
mPlayer. pause ( ) ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ if (mAudioManager != null ) {
+ mAudioManager. abandonAudioFocus ( null ) ;
+ }
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
} else if (mCurrentState == STATE_PREPARING ) {
mPauseDuringPreparing = true ;
}
@@ - 155, 6 + 172, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
if (mPlayer != null && mCurrentState != STATE_RELEASED ) {
mPlayer. release ( ) ;
mPlayer = null ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ if (mAudioManager != null ) {
+ mAudioManager. abandonAudioFocus ( null ) ;
+ }
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
}
mCurrentState = STATE_RELEASED ;
}
index 0e8a5db..3aa36b4 100755
--- a /HTML5VideoView. java
+++ b /HTML5VideoView. java
@@ - 17, 6 + 17, 10 @@
package android.webkit ;
import android.media.MediaPlayer ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ import android.media.AudioManager ;
+ import android.content.Context ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
import android.net.Uri ;
import android.webkit.HTML5VideoViewProxy ;
import java.io.IOException ;
@@ - 62, 6 + 66, 9 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
// player at the same time. We may recreate a new one and abandon the old
// one at transition time.
protected static MediaPlayer mPlayer = null ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ private static AudioManager mAudioManager = null ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
protected static int mCurrentState = - 1 ;
// We need to save such info.
@@ - 89, 6 + 96, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
mTimer. schedule ( new TimeupdateTask (mProxy ), TIMEUPDATE_PERIOD,
TIMEUPDATE_PERIOD ) ;
}
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ mAudioManager = (AudioManager ) mProxy. getContext ( ). getSystemService ( Context. AUDIO_SERVICE ) ;
+ mAudioManager. requestAudioFocus ( null, AudioManager. STREAM_MUSIC,
+ AudioManager. AUDIOFOCUS_GAIN_TRANSIENT ) ;
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
mPlayer. start ( ) ;
setPlayerBuffering ( false ) ;
}
@@ - 97, 6 + 109, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
public void pause ( ) {
if (isPlaying ( ) ) {
mPlayer. pause ( ) ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ if (mAudioManager != null ) {
+ mAudioManager. abandonAudioFocus ( null ) ;
+ }
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
} else if (mCurrentState == STATE_PREPARING ) {
mPauseDuringPreparing = true ;
}
@@ - 155, 6 + 172, 11 @@ public class HTML5VideoView implements MediaPlayer. OnPreparedListener {
if (mPlayer != null && mCurrentState != STATE_RELEASED ) {
mPlayer. release ( ) ;
mPlayer = null ;
+ // Begin: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @{
+ if (mAudioManager != null ) {
+ mAudioManager. abandonAudioFocus ( null ) ;
+ }
+ // End: [tianyu, 2013-08-23] Add for "Stop other voice while play online video" @}
}
mCurrentState = STATE_RELEASED ;
}