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

[video_player_web] Play videos from assets #2384

Merged
merged 10 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1

* Support videos from assets.

## 0.1.0+1

* Remove the deprecated `author:` field from pubspec.yaml
Expand Down
22 changes: 21 additions & 1 deletion packages/video_player/video_player_web/lib/video_player_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,28 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
final int textureId = _textureCounter;
_textureCounter++;

Uri uri;
switch (dataSource.sourceType) {
case DataSourceType.network:
uri = Uri.parse(dataSource.uri);
break;
case DataSourceType.asset:
String assetUrl = dataSource.asset;
if (dataSource.package != null && dataSource.package.isNotEmpty) {
assetUrl = 'packages/${dataSource.package}/$assetUrl';
}
// 'webOnlyAssetManager' is only in the web version of dart:ui
// ignore: undefined_prefixed_name
assetUrl = ui.webOnlyAssetManager.getAssetUrl(assetUrl);
uri = Uri.parse(assetUrl);
break;
case DataSourceType.file:
return Future.error(UnimplementedError(
'web implementation of video_player cannot play local files'));
}

final _VideoPlayer player = _VideoPlayer(
uri: Uri.parse(dataSource.uri),
uri: uri,
textureId: textureId,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: video_player_web
description: Web platform implementation of video_player
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_web
version: 0.1.0+1
version: 0.1.1

flutter:
plugin:
Expand All @@ -26,4 +26,4 @@ dev_dependencies:

environment:
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.10.0 <2.0.0"
flutter: ">=1.12.8 <2.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
expect(VideoPlayerPlatform.instance.init(), completes);
});

test('can create', () {
test('can create from network', () {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
Expand All @@ -44,6 +44,29 @@ void main() {
completion(isNonZero));
});

test('can create from asset', () {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
sourceType: DataSourceType.asset,
asset: 'videos/bee.mp4',
package: 'bee_vids',
),
),
completion(isNonZero));
});

test('cannot create from file', () {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
sourceType: DataSourceType.file,
uri: '/videos/bee.mp4',
),
),
throwsUnimplementedError);
});

test('can dispose', () {
expect(VideoPlayerPlatform.instance.dispose(textureId), completes);
});
Expand Down