提交 e7453c32 authored 作者: kongdywang's avatar kongdywang

1.fix ios background crash

2.android brightness range error 3.adjust flutter min version
上级 b3643cbf
group 'com.tencent.vod.flutter' group 'com.tencent.vod.flutter'
apply from:'config.gradle' apply from:'config.gradle'
apply plugin: 'com.android.library'
version rootProject.ext.playerVersion version rootProject.ext.playerVersion
buildscript { buildscript {
...@@ -20,9 +21,6 @@ rootProject.allprojects { ...@@ -20,9 +21,6 @@ rootProject.allprojects {
} }
} }
apply plugin: 'com.android.library'
android { android {
compileSdkVersion rootProject.ext.compileSdkVersion compileSdkVersion rootProject.ext.compileSdkVersion
......
...@@ -7,6 +7,7 @@ import android.content.ContentResolver; ...@@ -7,6 +7,7 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
...@@ -326,14 +327,33 @@ public class SuperPlayerPlugin implements FlutterPlugin, ActivityAware, ...@@ -326,14 +327,33 @@ public class SuperPlayerPlugin implements FlutterPlugin, ActivityAware,
float screenBrightness = -1; float screenBrightness = -1;
try { try {
ContentResolver resolver = mActivityPluginBinding.getActivity().getContentResolver(); ContentResolver resolver = mActivityPluginBinding.getActivity().getContentResolver();
int brightnessInt = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS); final int brightnessInt = Settings.System.getInt(resolver, Settings.System.SCREEN_BRIGHTNESS);
screenBrightness = brightnessInt / 255F; final float maxBrightness = getBrightnessMax();
screenBrightness = brightnessInt / maxBrightness;
} catch (SettingNotFoundException e) { } catch (SettingNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
return screenBrightness; return screenBrightness;
} }
/**
* 获取最大亮度,兼容部分系统亮度最大值不是255的情况,例如MIUI上最大值被改为了上千
*
* @return max
*/
private float getBrightnessMax() {
try {
Resources system = Resources.getSystem();
int resId = system.getIdentifier("config_screenBrightnessSettingMaximum", "integer", "android");
if (resId != 0) {
return system.getInteger(resId);
}
} catch (Exception e) {
Log.getStackTraceString(e);
}
return 255F;
}
private void initAudioManagerIfNeed() { private void initAudioManagerIfNeed() {
if (null == mTxAudioManager) { if (null == mTxAudioManager) {
mTxAudioManager = new FTXAudioManager(mFlutterPluginBinding.getApplicationContext()); mTxAudioManager = new FTXAudioManager(mFlutterPluginBinding.getApplicationContext());
......
## 环境准备 ## 环境准备
- Flutter 2.0 及以上版本。 - Flutter 3.0 及以上版本。
- Android 端开发: - Android 端开发:
- Android Studio 3.5及以上版本。 - Android Studio 3.5及以上版本。
- App 要求 Android 4.1及以上版本设备。 - App 要求 Android 4.1及以上版本设备。
......
...@@ -49,9 +49,9 @@ class _DemoTXVodPlayerState extends State<DemoTXVodPlayer> ...@@ -49,9 +49,9 @@ class _DemoTXVodPlayerState extends State<DemoTXVodPlayer>
if (event["event"] == TXVodPlayEvent.PLAY_EVT_RCV_FIRST_I_FRAME) { if (event["event"] == TXVodPlayEvent.PLAY_EVT_RCV_FIRST_I_FRAME) {
EasyLoading.dismiss(); EasyLoading.dismiss();
_supportedBitrates = (await _controller.getSupportedBitrates())!; _supportedBitrates = (await _controller.getSupportedBitrates())!;
_isPlaying = true;
_resizeVideo(event); _resizeVideo(event);
} else if (event["event"] == TXVodPlayEvent.PLAY_EVT_PLAY_PROGRESS) { } else if (event["event"] == TXVodPlayEvent.PLAY_EVT_PLAY_PROGRESS) {
_isPlaying = true;
_currentProgress = event[TXVodPlayEvent.EVT_PLAY_PROGRESS].toDouble(); _currentProgress = event[TXVodPlayEvent.EVT_PLAY_PROGRESS].toDouble();
double videoDuration = event[TXVodPlayEvent.EVT_PLAY_DURATION].toDouble(); // 总播放时长,转换后的单位 秒 double videoDuration = event[TXVodPlayEvent.EVT_PLAY_DURATION].toDouble(); // 总播放时长,转换后的单位 秒
if (videoDuration == 0.0) { if (videoDuration == 0.0) {
...@@ -112,15 +112,13 @@ class _DemoTXVodPlayerState extends State<DemoTXVodPlayer> ...@@ -112,15 +112,13 @@ class _DemoTXVodPlayerState extends State<DemoTXVodPlayer>
print("didChangeAppLifecycleState $state"); print("didChangeAppLifecycleState $state");
switch (state) { switch (state) {
case AppLifecycleState.inactive: case AppLifecycleState.inactive:
_controller.pause();
break; break;
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
if(_isPlaying) { if(_isPlaying) {
_controller.resume(); _controller.resume();
} }
break; break;
case AppLifecycleState.paused:
_controller.pause();
break;
default: default:
break; break;
} }
......
...@@ -6,8 +6,8 @@ description: Demonstrates how to use the super_player plugin. ...@@ -6,8 +6,8 @@ description: Demonstrates how to use the super_player plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.17.0 <4.0.0'
flutter: ">=2.0.0" flutter: ">=3.0.0"
dependencies: dependencies:
# 国际化 # 国际化
...@@ -16,7 +16,7 @@ dependencies: ...@@ -16,7 +16,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_easyloading: ^3.0.0 flutter_easyloading: ^3.0.5
super_player: super_player:
# When depending on this package from a real application you should use: # When depending on this package from a real application you should use:
......
...@@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar; - (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar;
- (void)notifyAppTerminate:(UIApplication *)application;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
......
...@@ -30,6 +30,8 @@ static const int uninitialized = -1; ...@@ -30,6 +30,8 @@ static const int uninitialized = -1;
id<FlutterPluginRegistrar> _registrar; id<FlutterPluginRegistrar> _registrar;
id<FlutterTextureRegistry> _textureRegistry; id<FlutterTextureRegistry> _textureRegistry;
BOOL _isTerminate;
BOOL _isStoped;
} }
- (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar - (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar
...@@ -38,6 +40,8 @@ static const int uninitialized = -1; ...@@ -38,6 +40,8 @@ static const int uninitialized = -1;
_registrar = registrar; _registrar = registrar;
_lastBuffer = nil; _lastBuffer = nil;
_latestPixelBuffer = nil; _latestPixelBuffer = nil;
_isTerminate = NO;
_isStoped = NO;
_textureId = -1; _textureId = -1;
_eventSink = [FTXPlayerEventSinkQueue new]; _eventSink = [FTXPlayerEventSinkQueue new];
_netStatusSink = [FTXPlayerEventSinkQueue new]; _netStatusSink = [FTXPlayerEventSinkQueue new];
...@@ -86,6 +90,11 @@ static const int uninitialized = -1; ...@@ -86,6 +90,11 @@ static const int uninitialized = -1;
_netStatusSink = nil; _netStatusSink = nil;
} }
- (void)notifyAppTerminate:(UIApplication *)application {
_isTerminate = YES;
_textureRegistry = nil;
}
- (void)setupPlayerWithBool:(BOOL)onlyAudio - (void)setupPlayerWithBool:(BOOL)onlyAudio
{ {
if (!onlyAudio) { if (!onlyAudio) {
...@@ -149,6 +158,7 @@ static const int uninitialized = -1; ...@@ -149,6 +158,7 @@ static const int uninitialized = -1;
- (int)startLivePlay:(NSString *)url type:(TX_Enum_PlayType)playType - (int)startLivePlay:(NSString *)url type:(TX_Enum_PlayType)playType
{ {
if (_txLivePlayer != nil) { if (_txLivePlayer != nil) {
_isStoped = NO;
return [_txLivePlayer startLivePlay:url type:playType]; return [_txLivePlayer startLivePlay:url type:playType];
} }
return uninitialized; return uninitialized;
...@@ -157,6 +167,7 @@ static const int uninitialized = -1; ...@@ -157,6 +167,7 @@ static const int uninitialized = -1;
- (BOOL)stopPlay - (BOOL)stopPlay
{ {
if (_txLivePlayer != nil) { if (_txLivePlayer != nil) {
_isStoped = YES;
return [_txLivePlayer stopPlay]; return [_txLivePlayer stopPlay];
} }
return NO; return NO;
...@@ -366,30 +377,31 @@ static const int uninitialized = -1; ...@@ -366,30 +377,31 @@ static const int uninitialized = -1;
*/ */
- (BOOL)onPlayerPixelBuffer:(CVPixelBufferRef)pixelBuffer - (BOOL)onPlayerPixelBuffer:(CVPixelBufferRef)pixelBuffer
{ {
if (_lastBuffer == nil) { if(!_isTerminate && !_isStoped) {
_lastBuffer = CVPixelBufferRetain(pixelBuffer); if (_lastBuffer == nil) {
CFRetain(pixelBuffer); _lastBuffer = CVPixelBufferRetain(pixelBuffer);
} else if (_lastBuffer != pixelBuffer) { CFRetain(pixelBuffer);
CVPixelBufferRelease(_lastBuffer); } else if (_lastBuffer != pixelBuffer) {
_lastBuffer = CVPixelBufferRetain(pixelBuffer); CVPixelBufferRelease(_lastBuffer);
CFRetain(pixelBuffer); _lastBuffer = CVPixelBufferRetain(pixelBuffer);
} CFRetain(pixelBuffer);
}
CVPixelBufferRef newBuffer = pixelBuffer; CVPixelBufferRef newBuffer = pixelBuffer;
CVPixelBufferRef old = _latestPixelBuffer; CVPixelBufferRef old = _latestPixelBuffer;
while (!OSAtomicCompareAndSwapPtrBarrier(old, newBuffer, while (!OSAtomicCompareAndSwapPtrBarrier(old, newBuffer,
(void **)&_latestPixelBuffer)) { (void **)&_latestPixelBuffer)) {
old = _latestPixelBuffer; old = _latestPixelBuffer;
} }
if (old && old != pixelBuffer) { if (old && old != pixelBuffer) {
CFRelease(old); CFRelease(old);
} }
if (_textureId >= 0) { if (_textureId >= 0 && _textureRegistry) {
[_textureRegistry textureFrameAvailable:_textureId]; [_textureRegistry textureFrameAvailable:_textureId];
}
} }
return NO; return NO;
} }
......
...@@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar; - (instancetype)initWithRegistrar:(id<FlutterPluginRegistrar>)registrar;
- (void)notifyAppTerminate:(UIApplication *)application;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
......
...@@ -20,6 +20,8 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -20,6 +20,8 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
@property (nonatomic, strong) UIView *txPipView; @property (nonatomic, strong) UIView *txPipView;
@property (nonatomic, assign) BOOL hasEnteredPipMode; @property (nonatomic, assign) BOOL hasEnteredPipMode;
@property (nonatomic, assign) BOOL restoreUI; @property (nonatomic, assign) BOOL restoreUI;
@property (atomic, assign) BOOL isStoped;
@property (atomic) BOOL isTerminate;
@end @end
/** /**
...@@ -59,6 +61,8 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -59,6 +61,8 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
isVideoFirstFrameReceived = false; isVideoFirstFrameReceived = false;
videoWidth = 0; videoWidth = 0;
videoHeight = 0; videoHeight = 0;
_isStoped = NO;
_isTerminate = NO;
playerMainqueue = dispatch_get_main_queue(); playerMainqueue = dispatch_get_main_queue();
self.hasEnteredPipMode = NO; self.hasEnteredPipMode = NO;
self.restoreUI = NO; self.restoreUI = NO;
...@@ -78,12 +82,18 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -78,12 +82,18 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
} }
- (void)onApplicationTerminateClick { - (void)onApplicationTerminateClick {
_isTerminate = YES;
[_txVodPlayer removeVideoWidget]; [_txVodPlayer removeVideoWidget];
_txVodPlayer = nil; _txVodPlayer = nil;
_txVodPlayer.videoProcessDelegate = nil; _txVodPlayer.videoProcessDelegate = nil;
_textureId = -1; _textureId = -1;
} }
- (void)notifyAppTerminate:(UIApplication *)application {
_isTerminate = YES;
_textureRegistry = nil;
}
- (void)destory - (void)destory
{ {
[self stopPlay]; [self stopPlay];
...@@ -108,7 +118,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -108,7 +118,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
if (old) { if (old) {
CFRelease(old); CFRelease(old);
} }
if (_lastBuffer) { if (_lastBuffer) {
CVPixelBufferRelease(_lastBuffer); CVPixelBufferRelease(_lastBuffer);
_lastBuffer = nil; _lastBuffer = nil;
...@@ -164,6 +174,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -164,6 +174,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
- (int)startVodPlay:(NSString *)url - (int)startVodPlay:(NSString *)url
{ {
if (_txVodPlayer != nil) { if (_txVodPlayer != nil) {
_isStoped = NO;
return [_txVodPlayer startVodPlay:url]; return [_txVodPlayer startVodPlay:url];
} }
return uninitialized; return uninitialized;
...@@ -178,6 +189,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -178,6 +189,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
if (sign.length > 0) { if (sign.length > 0) {
p.sign = sign; p.sign = sign;
} }
_isStoped = NO;
return [_txVodPlayer startVodPlayWithParams:p]; return [_txVodPlayer startVodPlayWithParams:p];
} }
return uninitialized; return uninitialized;
...@@ -186,6 +198,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -186,6 +198,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
- (BOOL)stopPlay - (BOOL)stopPlay
{ {
if (_txVodPlayer != nil) { if (_txVodPlayer != nil) {
_isStoped = YES;
return [_txVodPlayer stopPlay]; return [_txVodPlayer stopPlay];
} }
[self releaseImageSprite]; [self releaseImageSprite];
...@@ -441,7 +454,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -441,7 +454,7 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
*/ */
- (BOOL)onPlayerPixelBuffer:(CVPixelBufferRef)pixelBuffer - (BOOL)onPlayerPixelBuffer:(CVPixelBufferRef)pixelBuffer
{ {
if(pixelBuffer) { if(!_isTerminate && !_isStoped) {
if (_lastBuffer == nil) { if (_lastBuffer == nil) {
_lastBuffer = CVPixelBufferRetain(pixelBuffer); _lastBuffer = CVPixelBufferRetain(pixelBuffer);
CFRetain(pixelBuffer); CFRetain(pixelBuffer);
...@@ -462,11 +475,9 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003; ...@@ -462,11 +475,9 @@ static const int CODE_ON_RECEIVE_FIRST_FRAME = 2003;
if (old && old != pixelBuffer) { if (old && old != pixelBuffer) {
CFRelease(old); CFRelease(old);
} }
} else { if (_textureId >= 0 && _textureRegistry) {
NSLog(@"receive a nil pixel"); [_textureRegistry textureFrameAvailable:_textureId];
} }
if (_textureId >= 0 && nil != _textureRegistry) {
[_textureRegistry textureFrameAvailable:_textureId];
} }
return NO; return NO;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#import "FTXVodPlayerDispatcher.h" #import "FTXVodPlayerDispatcher.h"
#import "FTXLivePlayerDispatcher.h" #import "FTXLivePlayerDispatcher.h"
@interface SuperPlayerPlugin ()<FlutterStreamHandler,FTXVodPlayerDelegate,TXFlutterSuperPlayerPluginAPI,TXFlutterNativeAPI, IPlayersBridge> @interface SuperPlayerPlugin ()<FlutterStreamHandler,FTXVodPlayerDelegate,TXFlutterSuperPlayerPluginAPI,TXFlutterNativeAPI, IPlayersBridge, FlutterPlugin>
@property (nonatomic, strong) NSObject<FlutterPluginRegistrar>* registrar; @property (nonatomic, strong) NSObject<FlutterPluginRegistrar>* registrar;
@property (nonatomic, strong) NSMutableDictionary *players; @property (nonatomic, strong) NSMutableDictionary *players;
...@@ -39,6 +39,8 @@ SuperPlayerPlugin* instance; ...@@ -39,6 +39,8 @@ SuperPlayerPlugin* instance;
TXFlutterNativeAPISetup([registrar messenger], instance); TXFlutterNativeAPISetup([registrar messenger], instance);
TXFlutterVodPlayerApiSetup([registrar messenger], [[FTXVodPlayerDispatcher alloc] initWithBridge:instance]); TXFlutterVodPlayerApiSetup([registrar messenger], [[FTXVodPlayerDispatcher alloc] initWithBridge:instance]);
TXFlutterLivePlayerApiSetup([registrar messenger], [[FTXLivePlayerDispatcher alloc] initWithBridge:instance]); TXFlutterLivePlayerApiSetup([registrar messenger], [[FTXLivePlayerDispatcher alloc] initWithBridge:instance]);
[registrar addApplicationDelegate:self];
} }
- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar { - (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
...@@ -127,6 +129,17 @@ SuperPlayerPlugin* instance; ...@@ -127,6 +129,17 @@ SuperPlayerPlugin* instance;
[_eventSink success:[SuperPlayerPlugin getParamsWithEvent:EVENT_BRIGHTNESS_CHANGED withParams:@{}]]; [_eventSink success:[SuperPlayerPlugin getParamsWithEvent:EVENT_BRIGHTNESS_CHANGED withParams:@{}]];
} }
#pragma mark - FlutterPlugin
- (void)applicationWillTerminate:(UIApplication *)application {
for(id key in self.players) {
id player = self.players[key];
if([player respondsToSelector:@selector(notifyAppTerminate:)]) {
[player notifyAppTerminate:application];
}
}
}
#pragma mark - FlutterStreamHandler #pragma mark - FlutterStreamHandler
- (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments - (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments
eventSink:(FlutterEventSink)events eventSink:(FlutterEventSink)events
......
// Copyright (c) 2022 Tencent. All rights reserved.
part of SuperPlayer;
abstract class FPlayerPckInfo {
static const String PLAYER_VERSION = "11.1.1";
}
\ No newline at end of file
...@@ -141,6 +141,7 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX ...@@ -141,6 +141,7 @@ class TXVodPlayerController extends ChangeNotifier implements ValueListenable<TX
void printVersionInfo() async { void printVersionInfo() async {
LogUtils.d(kTag, "dart SDK version:${Platform.version}"); LogUtils.d(kTag, "dart SDK version:${Platform.version}");
LogUtils.d(kTag, "liteAV SDK version:${await SuperPlayerPlugin.platformVersion}"); LogUtils.d(kTag, "liteAV SDK version:${await SuperPlayerPlugin.platformVersion}");
LogUtils.d(kTag, "superPlayer SDK version:${FPlayerPckInfo.PLAYER_VERSION}");
} }
/// 通过url开始播放视频 /// 通过url开始播放视频
......
...@@ -24,4 +24,5 @@ part 'Core/txvoddownload_controller.dart'; ...@@ -24,4 +24,5 @@ part 'Core/txvoddownload_controller.dart';
part 'Core/txliveplayer_config.dart'; part 'Core/txliveplayer_config.dart';
part 'Core/tools/common_utils.dart'; part 'Core/tools/common_utils.dart';
part 'Core/provider/txplayer_holder.dart'; part 'Core/provider/txplayer_holder.dart';
part 'Core/txplayer_messages.dart'; part 'Core/txplayer_messages.dart';
\ No newline at end of file part 'Core/common/common_config.dart';
\ No newline at end of file
...@@ -5,8 +5,8 @@ author: ...@@ -5,8 +5,8 @@ author:
homepage: homepage:
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.17.0 <4.0.0'
flutter: ">=2.0.0" flutter: ">=3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -3,14 +3,14 @@ description: superplayer,base on vodplayer ...@@ -3,14 +3,14 @@ description: superplayer,base on vodplayer
version: "11.1.1" version: "11.1.1"
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.17.0 <4.0.0'
flutter: ">=2.0.0" flutter: ">=3.0.0"
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_easyloading: ^3.0.0 flutter_easyloading: ^3.0.5
super_player: super_player:
# When depending on this package from a real application you should use: # When depending on this package from a real application you should use:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论