Skip to content

Commit bb2e3e5

Browse files
committed
修复 ios的必须设置了autoPlay为true才能播放,设置了false后,在后面执行 controller.play()也不会播放
1 parent 5193b21 commit bb2e3e5

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

ios/flutter_tencentplayer.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ A new Flutter plugin.
1515
s.source_files = 'Classes/**/*'
1616
s.public_header_files = 'Classes/**/*.h'
1717
s.dependency 'Flutter'
18-
s.dependency 'TXLiteAVSDK_Player'
18+
# s.dependency 'TXLiteAVSDK_Player'
19+
s.dependency 'TXLiteAVSDK_Player', '= 6.8.7969'
1920
s.user_target_xcconfig = { 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES' }
2021
s.static_framework = true
2122
s.ios.deployment_target = '8.0'

lib/controller/tencent_player_controller.dart

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,11 @@ class TencentPlayerController extends ValueNotifier<TencentPlayerValue> {
1313
MethodChannel channel = TencentPlayer.channel;
1414

1515

16-
TencentPlayerController.asset(this.dataSource,
17-
{this.playerConfig = const PlayerConfig()})
18-
: dataSourceType = DataSourceType.asset,
19-
super(TencentPlayerValue());
16+
TencentPlayerController.asset(this.dataSource, {this.playerConfig = const PlayerConfig()}): dataSourceType = DataSourceType.asset, super(TencentPlayerValue());
2017

21-
TencentPlayerController.network(this.dataSource, {this.playerConfig = const PlayerConfig()}): dataSourceType = DataSourceType.network,
22-
super(TencentPlayerValue());
18+
TencentPlayerController.network(this.dataSource, {this.playerConfig = const PlayerConfig()}): dataSourceType = DataSourceType.network, super(TencentPlayerValue());
2319

24-
TencentPlayerController.file(String filePath,
25-
{this.playerConfig = const PlayerConfig()})
26-
: dataSource = filePath,
27-
dataSourceType = DataSourceType.file,
28-
super(TencentPlayerValue());
20+
TencentPlayerController.file(String filePath, {this.playerConfig = const PlayerConfig()}): dataSource = filePath, dataSourceType = DataSourceType.file, super(TencentPlayerValue());
2921

3022
bool _isDisposed = false;
3123
Completer<void> _creatingCompleter;
@@ -51,8 +43,7 @@ class TencentPlayerController extends ValueNotifier<TencentPlayerValue> {
5143
}
5244
value = value.copyWith(isPlaying: playerConfig.autoPlay);
5345
dataSourceDescription.addAll(playerConfig.toJson());
54-
final Map<String, dynamic> response =
55-
await channel.invokeMapMethod<String, dynamic>(
46+
final Map<String, dynamic> response = await channel.invokeMapMethod<String, dynamic>(
5647
'create',
5748
dataSourceDescription,
5849
);
@@ -99,9 +90,7 @@ class TencentPlayerController extends ValueNotifier<TencentPlayerValue> {
9990
}
10091
}
10192

102-
_eventSubscription = _eventChannelFor(_textureId)
103-
.receiveBroadcastStream()
104-
.listen(eventListener);
93+
_eventSubscription = _eventChannelFor(_textureId).receiveBroadcastStream().listen(eventListener);
10594
return initializingCompleter.future;
10695
}
10796

@@ -136,15 +125,14 @@ class TencentPlayerController extends ValueNotifier<TencentPlayerValue> {
136125
}
137126

138127
Future<void> _applyPlayPause() async {
139-
if (!value.initialized || _isDisposed) {
140-
return;
141-
}
128+
// if (!value.initialized || _isDisposed) {
129+
// if (!value.initialized) {
130+
// return;
131+
// }
142132
if (value.isPlaying) {
143-
await channel
144-
.invokeMethod('play', <String, dynamic>{'textureId': _textureId});
133+
await channel.invokeMethod('play', <String, dynamic>{'textureId': _textureId});
145134
} else {
146-
await channel
147-
.invokeMethod('pause', <String, dynamic>{'textureId': _textureId});
135+
await channel.invokeMethod('pause', <String, dynamic>{'textureId': _textureId});
148136
}
149137
}
150138

@@ -197,6 +185,7 @@ class TencentPlayerController extends ValueNotifier<TencentPlayerValue> {
197185
}
198186
}
199187

188+
///视频组件生命周期监听
200189
class _VideoAppLifeCycleObserver with WidgetsBindingObserver {
201190
bool _wasPlayingBeforePause = false;
202191
final TencentPlayerController _controller;

0 commit comments

Comments
 (0)