@@ -149,7 +149,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
149
149
/// The name of the asset is given by the [dataSource] argument and must not be
150
150
/// null. The [package] argument must be non-null when the asset comes from a
151
151
/// package and null otherwise.
152
- VideoPlayerController .asset (this .dataSource, {this .package})
152
+ VideoPlayerController .asset (this .dataSource,
153
+ {this .package, this .mixWithOthers})
153
154
: dataSourceType = DataSourceType .asset,
154
155
super (VideoPlayerValue (duration: null ));
155
156
@@ -158,7 +159,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
158
159
///
159
160
/// The URI for the video is given by the [dataSource] argument and must not be
160
161
/// null.
161
- VideoPlayerController .network (this .dataSource)
162
+ VideoPlayerController .network (this .dataSource, { this .mixWithOthers} )
162
163
: dataSourceType = DataSourceType .network,
163
164
package = null ,
164
165
super (VideoPlayerValue (duration: null ));
@@ -167,7 +168,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
167
168
///
168
169
/// This will load the file from the file-URI given by:
169
170
/// `'file://${file.path}'` .
170
- VideoPlayerController .file (File file)
171
+ VideoPlayerController .file (File file, { this .mixWithOthers} )
171
172
: dataSource = 'file://${file .path }' ,
172
173
dataSourceType = DataSourceType .file,
173
174
package = null ,
@@ -176,6 +177,10 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
176
177
int _textureId;
177
178
final String dataSource;
178
179
180
+ /// True if the video audio should be in mix mode (iOS only). False to stop all other
181
+ /// audio playback.
182
+ final bool mixWithOthers;
183
+
179
184
/// Describes the type of data source this [VideoPlayerController]
180
185
/// is constructed with.
181
186
final DataSourceType dataSourceType;
@@ -208,6 +213,11 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
208
213
case DataSourceType .file:
209
214
dataSourceDescription = < String , dynamic > {'uri' : dataSource};
210
215
}
216
+
217
+ if (mixWithOthers != null ) {
218
+ await _channel.invokeMethod ('setMixWithOthers' , mixWithOthers);
219
+ }
220
+
211
221
// TODO(amirh): remove this on when the invokeMethod update makes it to stable Flutter.
212
222
// https://github.com/flutter/flutter/issues/26431
213
223
// ignore: strong_mode_implicit_dynamic_method
@@ -236,7 +246,9 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
236
246
size: Size (map['width' ]? .toDouble () ?? 0.0 ,
237
247
map['height' ]? .toDouble () ?? 0.0 ),
238
248
);
239
- initializingCompleter.complete (null );
249
+ if (initializingCompleter.isCompleted == false ) {
250
+ initializingCompleter.complete (null );
251
+ }
240
252
_applyLooping ();
241
253
_applyVolume ();
242
254
_applyPlayPause ();
0 commit comments