Skip to content

Commit e0dee00

Browse files
author
dokieyang
committed
remove TXPhoneStateListener
1 parent 7cee917 commit e0dee00

File tree

1 file changed

+2
-114
lines changed

1 file changed

+2
-114
lines changed

Player-API-Example-Android/BaseVodPlayer/src/main/java/com/tencent/player/baseplayer/VodPlayerActivity.java

Lines changed: 2 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.tencent.player.baseplayer;
22

33
import android.app.Activity;
4-
import android.app.Application;
5-
import android.app.Service;
6-
import android.content.Context;
74
import android.content.Intent;
85
import android.graphics.Color;
96
import android.graphics.drawable.AnimationDrawable;
107
import android.net.Uri;
118
import android.os.Bundle;
129
import android.os.Handler;
13-
import android.telephony.PhoneStateListener;
14-
import android.telephony.TelephonyManager;
1510
import android.text.TextUtils;
1611
import android.util.Log;
1712
import android.view.ContextMenu;
@@ -28,12 +23,6 @@
2823

2924
import com.blankj.utilcode.constant.PermissionConstants;
3025
import com.blankj.utilcode.util.PermissionUtils;
31-
32-
import com.tencent.player.baseplayer.IntentUtils;
33-
import com.tencent.player.baseplayer.QRCodeScanActivity;
34-
import com.tencent.player.baseplayer.VideoQuality;
35-
import com.tencent.player.baseplayer.VideoQualityUtils;
36-
import com.tencent.player.baseplayer.VodQualityView;
3726
import com.tencent.rtmp.ITXVodPlayListener;
3827
import com.tencent.rtmp.TXBitrateItem;
3928
import com.tencent.rtmp.TXLiveConstants;
@@ -42,7 +31,6 @@
4231
import com.tencent.rtmp.TXVodPlayer;
4332
import com.tencent.rtmp.ui.TXCloudVideoView;
4433

45-
import java.lang.ref.WeakReference;
4634
import java.util.ArrayList;
4735
import java.util.Collections;
4836
import java.util.HashMap;
@@ -53,14 +41,13 @@ public class VodPlayerActivity extends Activity implements ITXVodPlayListener, V
5341
public static final int REQUEST_CODE_CONFIG = 101;
5442
private static final String TAG = "VodPlayerActivity";
5543
private static final String WEBRTC_LINK_URL = "https://cloud.tencent.com/document/product/454/12148";
56-
private static final String DEFAULT_PLAY_URL = "http://200024424.vod.myqcloud.com/200024424_709ae516bdf811e6ad39991f76a4df69.f20.mp4";
44+
private static final String DEFAULT_PLAY_URL = "http://1500005830.vod2.myqcloud.com/43843ec0vodtranscq1500005830/48d0f1f9387702299774251236/adp.10.m3u8";
5745
private static final String SPEED_FORMAT_TEMPLATE = "%.2f";
5846
private static final int MILLS_PER_SECOND = 1000;
5947
private static final int MILLS_PER_MINUTE = 60000;
6048
private static final int SEROND_PER_MINUTE = 60;
6149

6250
private TXVodPlayer mVodPlayer = null;
63-
private TXVodPlayer mVodPlayerPreload = null;
6451
private TXCloudVideoView mPlayerView;
6552
private ImageView mLoadingView;
6653
private LinearLayout mLinearRootView;
@@ -197,10 +184,6 @@ public void onClick(View v) {
197184
mVodPlayer = new TXVodPlayer(this);
198185
}
199186

200-
201-
mPhoneListener = new TXPhoneStateListener(this, mVodPlayer);
202-
mPhoneListener.startListen();
203-
204187
mPlayerView = (TXCloudVideoView) findViewById(R.id.video_view);
205188
mPlayerView.showLog(false);
206189
mPlayerView.setLogMargin(12, 12, 110, 60);
@@ -484,7 +467,6 @@ public void onDestroy() {
484467
}
485468
mPlayConfig = null;
486469
Log.d(TAG, "vrender onDestroy");
487-
mPhoneListener.stopListen();
488470
}
489471

490472
@Override
@@ -544,7 +526,7 @@ private boolean startPlayVod() {
544526
mVodPlayer.enableHardwareDecode(mHWDecode);
545527
mVodPlayer.setRenderRotation(mCurrentRenderRotation);
546528
mVodPlayer.setRenderMode(mCurrentRenderMode);
547-
mPlayConfig.setMediaType(TXVodConstants.MEDIA_TYPE_HLS_VOD);
529+
mPlayConfig.setMediaType(TXVodConstants.MEDIA_TYPE_AUTO);
548530
if (mEnableCache) {
549531
mPlayConfig.setCacheFolderPath(getInnerSDCardPath() + "/txcache");
550532
mPlayConfig.setMaxCacheItems(1);
@@ -634,10 +616,6 @@ public void onPlayEvent(TXVodPlayer player, int event, Bundle param) {
634616
if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) {
635617
stopLoadingAnimation();
636618
Log.d("AutoMonitor", "PlayFirstRender,cost=" + (System.currentTimeMillis() - mStartPlayTS));
637-
if (mPhoneListener.isInBackground()) {
638-
mVodPlayer.pause();
639-
}
640-
641619

642620
} else if (event == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS) {
643621
if (mStartSeek) {
@@ -676,9 +654,6 @@ public void onPlayEvent(TXVodPlayer player, int event, Bundle param) {
676654
} else if (event == TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME) {
677655
stopLoadingAnimation();
678656
findViewById(R.id.playerHeaderView).setVisibility(View.GONE);
679-
if (mPhoneListener.isInBackground()) {
680-
mVodPlayer.pause();
681-
}
682657
} else if (event == TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION) {
683658
} else if (event == TXLiveConstants.PLAY_ERR_HLS_KEY) {//HLS 解密 key 获取失败
684659
stopPlayVod();
@@ -736,93 +711,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
736711
}
737712

738713

739-
static class TXPhoneStateListener extends PhoneStateListener implements Application.ActivityLifecycleCallbacks {
740-
WeakReference<TXVodPlayer> mPlayer;
741-
Context mContext;
742-
int activityCount;
743-
744-
public TXPhoneStateListener(Context context, TXVodPlayer player) {
745-
mPlayer = new WeakReference<>(player);
746-
mContext = context.getApplicationContext();
747-
}
748-
749-
public void startListen() {
750-
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Service.TELEPHONY_SERVICE);
751-
tm.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
752-
}
753-
754-
public void stopListen() {
755-
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Service.TELEPHONY_SERVICE);
756-
tm.listen(this, PhoneStateListener.LISTEN_NONE);
757-
}
758-
759-
@Override
760-
public void onCallStateChanged(int state, String incomingNumber) {
761-
super.onCallStateChanged(state, incomingNumber);
762-
TXVodPlayer player = mPlayer.get();
763-
switch (state) {
764-
//电话等待接听
765-
case TelephonyManager.CALL_STATE_RINGING:
766-
Log.d(TAG, "CALL_STATE_RINGING");
767-
if (player != null) player.pause();
768-
break;
769-
//电话接听
770-
case TelephonyManager.CALL_STATE_OFFHOOK:
771-
Log.d(TAG, "CALL_STATE_OFFHOOK");
772-
if (player != null) player.pause();
773-
break;
774-
//电话挂机
775-
case TelephonyManager.CALL_STATE_IDLE:
776-
Log.d(TAG, "CALL_STATE_IDLE");
777-
if (player != null && activityCount >= 0) player.resume();
778-
break;
779-
}
780-
}
781-
782-
@Override
783-
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
784-
785-
}
786-
787-
@Override
788-
public void onActivityPaused(Activity activity) {
789-
790-
}
791-
792-
@Override
793-
public void onActivityDestroyed(Activity activity) {
794-
795-
}
796-
797-
@Override
798-
public void onActivityResumed(Activity activity) {
799-
activityCount++;
800-
Log.d(TAG, "onActivityResumed" + activityCount);
801-
}
802-
803-
@Override
804-
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
805-
806-
}
807-
808-
@Override
809-
public void onActivityStarted(Activity activity) {
810-
811-
}
812-
813-
@Override
814-
public void onActivityStopped(Activity activity) {
815-
activityCount--;
816-
Log.d(TAG, "onActivityStopped" + activityCount);
817-
}
818-
819-
boolean isInBackground() {
820-
return (activityCount < 0);
821-
}
822-
}
823-
824-
private TXPhoneStateListener mPhoneListener = null;
825-
826714
@Override
827715
public void onQualitySelect(VideoQuality quality) {
828716
updateVideoQuality(quality);

0 commit comments

Comments
 (0)