From e0dee0091a95d3e5a53a24406ee1f8141454cf93 Mon Sep 17 00:00:00 2001 From: dokieyang Date: Tue, 12 Dec 2023 14:52:04 +0800 Subject: [PATCH] remove TXPhoneStateListener --- .../player/baseplayer/VodPlayerActivity.java | 116 +----------------- 1 file changed, 2 insertions(+), 114 deletions(-) diff --git a/Player-API-Example-Android/BaseVodPlayer/src/main/java/com/tencent/player/baseplayer/VodPlayerActivity.java b/Player-API-Example-Android/BaseVodPlayer/src/main/java/com/tencent/player/baseplayer/VodPlayerActivity.java index 7eac26f..ca2b244 100644 --- a/Player-API-Example-Android/BaseVodPlayer/src/main/java/com/tencent/player/baseplayer/VodPlayerActivity.java +++ b/Player-API-Example-Android/BaseVodPlayer/src/main/java/com/tencent/player/baseplayer/VodPlayerActivity.java @@ -1,17 +1,12 @@ package com.tencent.player.baseplayer; import android.app.Activity; -import android.app.Application; -import android.app.Service; -import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.AnimationDrawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.telephony.PhoneStateListener; -import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; import android.view.ContextMenu; @@ -28,12 +23,6 @@ import com.blankj.utilcode.constant.PermissionConstants; import com.blankj.utilcode.util.PermissionUtils; - -import com.tencent.player.baseplayer.IntentUtils; -import com.tencent.player.baseplayer.QRCodeScanActivity; -import com.tencent.player.baseplayer.VideoQuality; -import com.tencent.player.baseplayer.VideoQualityUtils; -import com.tencent.player.baseplayer.VodQualityView; import com.tencent.rtmp.ITXVodPlayListener; import com.tencent.rtmp.TXBitrateItem; import com.tencent.rtmp.TXLiveConstants; @@ -42,7 +31,6 @@ import com.tencent.rtmp.TXVodPlayer; import com.tencent.rtmp.ui.TXCloudVideoView; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -53,14 +41,13 @@ public class VodPlayerActivity extends Activity implements ITXVodPlayListener, V public static final int REQUEST_CODE_CONFIG = 101; private static final String TAG = "VodPlayerActivity"; private static final String WEBRTC_LINK_URL = "https://cloud.tencent.com/document/product/454/12148"; - private static final String DEFAULT_PLAY_URL = "http://200024424.vod.myqcloud.com/200024424_709ae516bdf811e6ad39991f76a4df69.f20.mp4"; + private static final String DEFAULT_PLAY_URL = "http://1500005830.vod2.myqcloud.com/43843ec0vodtranscq1500005830/48d0f1f9387702299774251236/adp.10.m3u8"; private static final String SPEED_FORMAT_TEMPLATE = "%.2f"; private static final int MILLS_PER_SECOND = 1000; private static final int MILLS_PER_MINUTE = 60000; private static final int SEROND_PER_MINUTE = 60; private TXVodPlayer mVodPlayer = null; - private TXVodPlayer mVodPlayerPreload = null; private TXCloudVideoView mPlayerView; private ImageView mLoadingView; private LinearLayout mLinearRootView; @@ -197,10 +184,6 @@ public void onClick(View v) { mVodPlayer = new TXVodPlayer(this); } - - mPhoneListener = new TXPhoneStateListener(this, mVodPlayer); - mPhoneListener.startListen(); - mPlayerView = (TXCloudVideoView) findViewById(R.id.video_view); mPlayerView.showLog(false); mPlayerView.setLogMargin(12, 12, 110, 60); @@ -484,7 +467,6 @@ public void onDestroy() { } mPlayConfig = null; Log.d(TAG, "vrender onDestroy"); - mPhoneListener.stopListen(); } @Override @@ -544,7 +526,7 @@ private boolean startPlayVod() { mVodPlayer.enableHardwareDecode(mHWDecode); mVodPlayer.setRenderRotation(mCurrentRenderRotation); mVodPlayer.setRenderMode(mCurrentRenderMode); - mPlayConfig.setMediaType(TXVodConstants.MEDIA_TYPE_HLS_VOD); + mPlayConfig.setMediaType(TXVodConstants.MEDIA_TYPE_AUTO); if (mEnableCache) { mPlayConfig.setCacheFolderPath(getInnerSDCardPath() + "/txcache"); mPlayConfig.setMaxCacheItems(1); @@ -634,10 +616,6 @@ public void onPlayEvent(TXVodPlayer player, int event, Bundle param) { if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) { stopLoadingAnimation(); Log.d("AutoMonitor", "PlayFirstRender,cost=" + (System.currentTimeMillis() - mStartPlayTS)); - if (mPhoneListener.isInBackground()) { - mVodPlayer.pause(); - } - } else if (event == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS) { if (mStartSeek) { @@ -676,9 +654,6 @@ public void onPlayEvent(TXVodPlayer player, int event, Bundle param) { } else if (event == TXLiveConstants.PLAY_EVT_RCV_FIRST_I_FRAME) { stopLoadingAnimation(); findViewById(R.id.playerHeaderView).setVisibility(View.GONE); - if (mPhoneListener.isInBackground()) { - mVodPlayer.pause(); - } } else if (event == TXLiveConstants.PLAY_EVT_CHANGE_RESOLUTION) { } else if (event == TXLiveConstants.PLAY_ERR_HLS_KEY) {//HLS 解密 key 获取失败 stopPlayVod(); @@ -736,93 +711,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } - static class TXPhoneStateListener extends PhoneStateListener implements Application.ActivityLifecycleCallbacks { - WeakReference mPlayer; - Context mContext; - int activityCount; - - public TXPhoneStateListener(Context context, TXVodPlayer player) { - mPlayer = new WeakReference<>(player); - mContext = context.getApplicationContext(); - } - - public void startListen() { - TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Service.TELEPHONY_SERVICE); - tm.listen(this, PhoneStateListener.LISTEN_CALL_STATE); - } - - public void stopListen() { - TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Service.TELEPHONY_SERVICE); - tm.listen(this, PhoneStateListener.LISTEN_NONE); - } - - @Override - public void onCallStateChanged(int state, String incomingNumber) { - super.onCallStateChanged(state, incomingNumber); - TXVodPlayer player = mPlayer.get(); - switch (state) { - //电话等待接听 - case TelephonyManager.CALL_STATE_RINGING: - Log.d(TAG, "CALL_STATE_RINGING"); - if (player != null) player.pause(); - break; - //电话接听 - case TelephonyManager.CALL_STATE_OFFHOOK: - Log.d(TAG, "CALL_STATE_OFFHOOK"); - if (player != null) player.pause(); - break; - //电话挂机 - case TelephonyManager.CALL_STATE_IDLE: - Log.d(TAG, "CALL_STATE_IDLE"); - if (player != null && activityCount >= 0) player.resume(); - break; - } - } - - @Override - public void onActivityCreated(Activity activity, Bundle savedInstanceState) { - - } - - @Override - public void onActivityPaused(Activity activity) { - - } - - @Override - public void onActivityDestroyed(Activity activity) { - - } - - @Override - public void onActivityResumed(Activity activity) { - activityCount++; - Log.d(TAG, "onActivityResumed" + activityCount); - } - - @Override - public void onActivitySaveInstanceState(Activity activity, Bundle outState) { - - } - - @Override - public void onActivityStarted(Activity activity) { - - } - - @Override - public void onActivityStopped(Activity activity) { - activityCount--; - Log.d(TAG, "onActivityStopped" + activityCount); - } - - boolean isInBackground() { - return (activityCount < 0); - } - } - - private TXPhoneStateListener mPhoneListener = null; - @Override public void onQualitySelect(VideoQuality quality) { updateVideoQuality(quality);