33// found in the LICENSE file.
44
55import 'dart:async' ;
6+ import 'dart:io' ;
67
78import 'package:flutter/services.dart' ;
89import '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 {
133136class 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 );
0 commit comments