提交 4326ba38 authored 作者: kongdywang's avatar kongdywang

1.fix ios background crash

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