Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 24c042e

Browse files
author
Harry Terkelsen
authored
[video_player_web] Play videos from assets (#2384)
* [video_player_web] Add support for asset DataSources * Roll pub version * Remove deprecated author field * Respond to review comments * Add back author field * Delete author field again * Fix pubspecs * Fix handling of packages * add back author to platform interface we will fix this when we update the pubspecs for this package
1 parent fd5832b commit 24c042e

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

packages/video_player/video_player_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.1
2+
3+
* Support videos from assets.
4+
15
## 0.1.0+1
26

37
* Remove the deprecated `author:` field from pubspec.yaml

packages/video_player/video_player_web/lib/video_player_web.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,28 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
4242
final int textureId = _textureCounter;
4343
_textureCounter++;
4444

45+
Uri uri;
46+
switch (dataSource.sourceType) {
47+
case DataSourceType.network:
48+
uri = Uri.parse(dataSource.uri);
49+
break;
50+
case DataSourceType.asset:
51+
String assetUrl = dataSource.asset;
52+
if (dataSource.package != null && dataSource.package.isNotEmpty) {
53+
assetUrl = 'packages/${dataSource.package}/$assetUrl';
54+
}
55+
// 'webOnlyAssetManager' is only in the web version of dart:ui
56+
// ignore: undefined_prefixed_name
57+
assetUrl = ui.webOnlyAssetManager.getAssetUrl(assetUrl);
58+
uri = Uri.parse(assetUrl);
59+
break;
60+
case DataSourceType.file:
61+
return Future.error(UnimplementedError(
62+
'web implementation of video_player cannot play local files'));
63+
}
64+
4565
final _VideoPlayer player = _VideoPlayer(
46-
uri: Uri.parse(dataSource.uri),
66+
uri: uri,
4767
textureId: textureId,
4868
);
4969

packages/video_player/video_player_web/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: video_player_web
22
description: Web platform implementation of video_player
33
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_web
4-
version: 0.1.0+1
4+
version: 0.1.1
55

66
flutter:
77
plugin:
@@ -26,4 +26,4 @@ dev_dependencies:
2626

2727
environment:
2828
sdk: ">=2.0.0-dev.28.0 <3.0.0"
29-
flutter: ">=1.10.0 <2.0.0"
29+
flutter: ">=1.12.8 <2.0.0"

packages/video_player/video_player_web/test/video_player_web_test.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333
expect(VideoPlayerPlatform.instance.init(), completes);
3434
});
3535

36-
test('can create', () {
36+
test('can create from network', () {
3737
expect(
3838
VideoPlayerPlatform.instance.create(
3939
DataSource(
@@ -44,6 +44,29 @@ void main() {
4444
completion(isNonZero));
4545
});
4646

47+
test('can create from asset', () {
48+
expect(
49+
VideoPlayerPlatform.instance.create(
50+
DataSource(
51+
sourceType: DataSourceType.asset,
52+
asset: 'videos/bee.mp4',
53+
package: 'bee_vids',
54+
),
55+
),
56+
completion(isNonZero));
57+
});
58+
59+
test('cannot create from file', () {
60+
expect(
61+
VideoPlayerPlatform.instance.create(
62+
DataSource(
63+
sourceType: DataSourceType.file,
64+
uri: '/videos/bee.mp4',
65+
),
66+
),
67+
throwsUnimplementedError);
68+
});
69+
4770
test('can dispose', () {
4871
expect(VideoPlayerPlatform.instance.dispose(textureId), completes);
4972
});

0 commit comments

Comments
 (0)