Skip to content

Commit ace5001

Browse files
authored
Add constructor VideoPlayerController.file() (flutter#493)
Add constructor VideoPlayerController.file
1 parent 8eccba4 commit ace5001

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

packages/video_player/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.5.0
2+
3+
* Added the constructor `VideoPlayerController.file`.
4+
* **Breaking change**. Changed `VideoPlayerController.isNetwork` to
5+
an enum `VideoPlayerController.dataSourceType`.
6+
17
## 0.4.1
28

39
* Updated Flutter SDK constraint to reflect the changes in v0.4.0.

packages/video_player/lib/video_player.dart

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:io';
67

78
import 'package:flutter/services.dart';
89
import 'package:flutter/material.dart';
@@ -120,6 +121,8 @@ class VideoPlayerValue {
120121
}
121122
}
122123

124+
enum DataSourceType { asset, network, file }
125+
123126
/// Controls a platform video player, and provides updates when the state is
124127
/// changing.
125128
///
@@ -133,7 +136,11 @@ class VideoPlayerValue {
133136
class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
134137
int _textureId;
135138
final String dataSource;
136-
final bool isNetwork;
139+
140+
/// Describes the type of data source this [VideoPlayerController]
141+
/// is constructed with.
142+
final DataSourceType dataSourceType;
143+
137144
String package;
138145
Timer timer;
139146
bool isDisposed = false;
@@ -147,7 +154,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
147154
/// null. The [package] argument must be non-null when the asset comes from a
148155
/// package and null otherwise.
149156
VideoPlayerController.asset(this.dataSource, {this.package})
150-
: isNetwork = false,
157+
: dataSourceType = DataSourceType.asset,
151158
super(new VideoPlayerValue(duration: null));
152159

153160
/// Constructs a [VideoPlayerController] playing a video from obtained from
@@ -156,18 +163,39 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
156163
/// The URI for the video is given by the [dataSource] argument and must not be
157164
/// null.
158165
VideoPlayerController.network(this.dataSource)
159-
: isNetwork = true,
166+
: dataSourceType = DataSourceType.network,
167+
super(new VideoPlayerValue(duration: null));
168+
169+
/// Constructs a [VideoPlayerController] playing a video from a file.
170+
///
171+
/// This will load the file from the file-URI given by:
172+
/// `'file://${file.path}'`.
173+
VideoPlayerController.file(File file)
174+
: dataSource = 'file://${file.path}',
175+
dataSourceType = DataSourceType.file,
160176
super(new VideoPlayerValue(duration: null));
161177

162178
Future<Null> initialize() async {
163179
_lifeCycleObserver = new _VideoAppLifeCycleObserver(this);
164180
_lifeCycleObserver.initialize();
165181
_creatingCompleter = new Completer<Null>();
182+
Map<dynamic, dynamic> dataSourceDescription;
183+
switch (dataSourceType) {
184+
case DataSourceType.asset:
185+
dataSourceDescription = <String, dynamic>{
186+
'asset': dataSource,
187+
'package': package
188+
};
189+
break;
190+
case DataSourceType.network:
191+
dataSourceDescription = <String, dynamic>{'uri': dataSource};
192+
break;
193+
case DataSourceType.file:
194+
dataSourceDescription = <String, dynamic>{'uri': dataSource};
195+
}
166196
final Map<dynamic, dynamic> response = await _channel.invokeMethod(
167197
'create',
168-
isNetwork
169-
? <String, dynamic>{'uri': dataSource}
170-
: <String, dynamic>{'asset': dataSource, 'package': package},
198+
dataSourceDescription,
171199
);
172200
_textureId = response['textureId'];
173201
_creatingCompleter.complete(null);

packages/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player
22
description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android and iOS.
44
author: Flutter Team <flutter-dev@googlegroups.com>
5-
version: 0.4.1
5+
version: 0.5.0
66
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player
77

88
flutter:

0 commit comments

Comments
 (0)