安卓浏览器网页播放视频时后台声音不停止
来源:互联网 发布:wubi安装ubuntu 编辑:程序博客网 时间:2024/05/02 00:00
出自: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;
}
0 0
- 安卓浏览器网页播放视频时后台声音不停止
- 浏览器播放视频没声音
- 网页中播放声音/视频
- 推送时,播放震动声音不停止的代码
- Android使用WebView浏览有声音或者视频的网页,关闭WebView之后,声音或者视频不停止的解决办法
- Android使用WebView浏览有声音或者视频的网页,关闭WebView之后,声音或者视频不停止的解决办法
- Android视频播放时停止后台运行的方法
- unity3d 安卓播放视频不使用视频纹理
- Android使用WebView浏览有声音或者视频的网页,关闭WebView或者当前界面之后,声音或者视频不停止
- Android使用WebView浏览有声音或者视频的网页,关闭WebView或者当前界面之后,声音或者视频不停止
- 安卓WebView中全屏播放网页视频
- 安卓WebView中全屏播放网页视频
- 在手机浏览器上jplayer全屏播放视频设置在播放完成或者中间停止播放后手机浏览器的网页不能上下滚屏的解决
- Android 关闭WebView之后 ,声音或者视频不停止
- Xamarin 安卓VideoView 播放视频有声音无图像(已解决)
- XP浏览网页视频时没有声音,但是系统下是可以播放的问题
- 网页视频播放时是绿色的 有声音没图像的解决办法
- 怎么解决网页中播放视频没有声音?
- [Leetcode] 56. Merge Intervals
- 《JAVA与模式》之策略模式
- Linux网络编程——网络协议入门
- [Leetcode] 57. Insert Interval
- 《JAVA与模式》之模板方法模式
- 安卓浏览器网页播放视频时后台声音不停止
- ssh private key
- ios-day15-05(Quartz 2D之一张图片以平铺或者填充的方式设置为UIView的背景、以填充的方式为UIView设置条纹背景)
- [Leetcode] 58. Length of Last Word
- 《JAVA与模式》之观察者模式
- android webkit HTML5 video研究
- 存储过程、函数、触发器
- 《JAVA与模式》之迭代子模式
- redis配置文件详解