提交 1e28cabf authored 作者: kongdywang's avatar kongdywang

fix bug about volume and live

上级 a3fbe87c
...@@ -81,15 +81,16 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO ...@@ -81,15 +81,16 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO
await SuperPlayerPlugin.setConsoleEnabled(true); await SuperPlayerPlugin.setConsoleEnabled(true);
await _controller.initialize(); await _controller.initialize();
await _controller.setConfig(FTXLivePlayConfig());
// 安卓需要设置hls格式才可正常播放 // 安卓需要设置hls格式才可正常播放
await _controller.play(_url, playType: TXPlayType.LIVE_FLV); await _controller.startPlay(_url, playType: TXPlayType.LIVE_FLV);
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
init(); init();
WidgetsBinding.instance?.addObserver(this); WidgetsBinding.instance.addObserver(this);
EasyLoading.show(status: 'loading...'); EasyLoading.show(status: 'loading...');
} }
...@@ -207,7 +208,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO ...@@ -207,7 +208,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO
), ),
new GestureDetector( new GestureDetector(
onTap: () async { onTap: () async {
_controller.play(_url, playType: TXPlayType.LIVE_FLV); _controller.startPlay(_url, playType: TXPlayType.LIVE_FLV);
}, },
child: Container( child: Container(
color: Colors.transparent, color: Colors.transparent,
...@@ -290,7 +291,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO ...@@ -290,7 +291,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO
playNetEventSubscription?.cancel(); playNetEventSubscription?.cancel();
_controller.dispose(); _controller.dispose();
super.dispose(); super.dispose();
WidgetsBinding.instance?.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
EasyLoading.dismiss(); EasyLoading.dismiss();
} }
...@@ -302,7 +303,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO ...@@ -302,7 +303,7 @@ class _DemoTXLivelayerState extends State<DemoTXLivePlayer> with WidgetsBindingO
_url = url; _url = url;
_controller.stop(); _controller.stop();
if (url.isNotEmpty) { if (url.isNotEmpty) {
_controller.play(url); _controller.startPlay(url);
} }
}, showFileEdited: false); }, showFileEdited: false);
}); });
......
...@@ -12,10 +12,8 @@ ...@@ -12,10 +12,8 @@
- (void)setVolumeUIVisible:(BOOL)volumeUIVisible; - (void)setVolumeUIVisible:(BOOL)volumeUIVisible;
- (void)registerVolumeChangeListener:(_Nonnull id)observer selector:(_Nonnull SEL)aSelector - (void)registerVolumeChangeListener:(_Nonnull id)observer;
name:(nullable NSNotificationName)aName object:(nullable id)anObject;
- (void)destory:(_Nonnull id)observer name:(nullable NSNotificationName)aName - (void)destory:(_Nonnull id)observer;
object:(nullable id)anObject;
@end @end
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
@implementation FTXAudioManager @implementation FTXAudioManager
UISlider *_volumeSlider; UISlider *_volumeSlider;
MPVolumeView *volumeView; MPVolumeView *volumeView;
AVAudioSession *audioSession;
NSString *const LOW_VERSION_NOTIFCATION_NAME = @"AVSystemController_SystemVolumeDidChangeNotification";
NSString *const NOTIFCATION_NAME = @"SystemVolumeDidChange";
- (instancetype)init - (instancetype)init
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
@implementation FTXTransformation @implementation FTXTransformation
+ (TXVodPlayConfig *)transformToConfig:(NSDictionary *)args + (TXVodPlayConfig *)transformToVodConfig:(NSDictionary *)args
{ {
TXVodPlayConfig *playConfig = [[TXVodPlayConfig alloc] init]; TXVodPlayConfig *playConfig = [[TXVodPlayConfig alloc] init];
playConfig.connectRetryCount = [args[@"config"][@"connectRetryCount"] intValue]; playConfig.connectRetryCount = [args[@"config"][@"connectRetryCount"] intValue];
...@@ -48,6 +48,29 @@ ...@@ -48,6 +48,29 @@
return playConfig; return playConfig;
} }
+ (TXLivePlayConfig *)transformToLiveConfig:(NSDictionary *)args
{
TXLivePlayConfig *playConfig = [[TXLivePlayConfig alloc] init];
playConfig.cacheTime = [args[@"config"][@"cacheTime"] floatValue];
playConfig.maxAutoAdjustCacheTime = [args[@"config"][@"maxAutoAdjustCacheTime"] floatValue];
playConfig.minAutoAdjustCacheTime = [args[@"config"][@"minAutoAdjustCacheTime"] floatValue];
playConfig.videoBlockThreshold = [args[@"config"][@"videoBlockThreshold"] intValue];
playConfig.connectRetryCount = [args[@"config"][@"connectRetryCount"] intValue];
playConfig.connectRetryInterval = [args[@"config"][@"connectRetryInterval"] intValue];
playConfig.bAutoAdjustCacheTime = [args[@"config"][@"autoAdjustCacheTime"] boolValue];
playConfig.enableAEC = [args[@"config"][@"enableAec"] boolValue];
playConfig.enableMessage = [args[@"config"][@"enableMessage"] intValue];
playConfig.enableMetaData = [args[@"config"][@"enableMetaData"] intValue];
NSString *flvSessionKey = args[@"config"][@"flvSessionKey"];
if(flvSessionKey != nil && flvSessionKey.length > 0) {
playConfig.flvSessionKey = flvSessionKey;
}
return playConfig;
}
@end @end
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#import "FTXTransformation.h" #import "FTXTransformation.h"
#import "FTXPlayerEventSinkQueue.h" #import "FTXPlayerEventSinkQueue.h"
#import "FTXEvent.h" #import "FTXEvent.h"
#import "FTXAudioManager.h" #import <MediaPlayer/MediaPlayer.h>
#import <TXLiteAVSDK_Player/TXLiteAVSDK.h> #import <TXLiteAVSDK_Player/TXLiteAVSDK.h>
#import "FTXAudioManager.h"
#import "FTXDownloadManager.h" #import "FTXDownloadManager.h"
@interface SuperPlayerPlugin ()<FlutterStreamHandler,FTXVodPlayerDelegate> @interface SuperPlayerPlugin ()<FlutterStreamHandler,FTXVodPlayerDelegate>
...@@ -64,10 +65,9 @@ SuperPlayerPlugin* instance; ...@@ -64,10 +65,9 @@ SuperPlayerPlugin* instance;
_eventChannel = [FlutterEventChannel eventChannelWithName:@"cloud.tencent.com/playerPlugin/event" binaryMessenger:[registrar messenger]]; _eventChannel = [FlutterEventChannel eventChannelWithName:@"cloud.tencent.com/playerPlugin/event" binaryMessenger:[registrar messenger]];
_pipEventChannel = [FlutterEventChannel eventChannelWithName:@"cloud.tencent.com/playerPlugin/pipEvent" binaryMessenger:[registrar messenger]]; _pipEventChannel = [FlutterEventChannel eventChannelWithName:@"cloud.tencent.com/playerPlugin/pipEvent" binaryMessenger:[registrar messenger]];
[_eventChannel setStreamHandler:self]; [_eventChannel setStreamHandler:self];
[audioManager registerVolumeChangeListener:self selector:@selector(systemVolumeDidChangeNoti:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
// pip
[_pipEventChannel setStreamHandler:self]; [_pipEventChannel setStreamHandler:self];
// download
[audioManager registerVolumeChangeListener:self];
_FTXDownloadManager = [[FTXDownloadManager alloc] initWithRegistrar:registrar]; _FTXDownloadManager = [[FTXDownloadManager alloc] initWithRegistrar:registrar];
// orientation // orientation
mCurrentOrientation = ORIENTATION_PORTRAIT_UP; mCurrentOrientation = ORIENTATION_PORTRAIT_UP;
...@@ -79,7 +79,8 @@ SuperPlayerPlugin* instance; ...@@ -79,7 +79,8 @@ SuperPlayerPlugin* instance;
return self; return self;
} }
-(void)systemVolumeDidChangeNoti:(NSNotification* )noti{ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
{
[_eventSink success:[SuperPlayerPlugin getParamsWithEvent:EVENT_VOLUME_CHANGED withParams:@{}]]; [_eventSink success:[SuperPlayerPlugin getParamsWithEvent:EVENT_VOLUME_CHANGED withParams:@{}]];
} }
...@@ -207,7 +208,7 @@ SuperPlayerPlugin* instance; ...@@ -207,7 +208,7 @@ SuperPlayerPlugin* instance;
-(void) destory -(void) destory
{ {
[audioManager destory:self name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil]; [audioManager destory:self];
} }
#pragma mark - FlutterStreamHandler #pragma mark - FlutterStreamHandler
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论