Skip to content

Commit cba3932

Browse files
cbenhagenHarry Terkelsen
authored and
Harry Terkelsen
committed
[video_player] Add platform interface (flutter#2273)
* Move plugin to subdir * Add video_player_platform_interface * Make analyzer happy * Improve documentation * Bump version and update changelog * Add stream of VideoEvent * Ignore deprecated_member_use * Improve changelog message and version * Use DataSource class * Add duration, size and buffering to VideoEvent * Seek to Duration * Fix buffering update * Adapt docstring * Add buildView
1 parent d28c98c commit cba3932

File tree

88 files changed

+725
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+725
-3
lines changed

packages/video_player/CHANGELOG.md renamed to packages/video_player/video_player/CHANGELOG.md

+4

packages/video_player/README.md renamed to packages/video_player/video_player/README.md

+1-1

packages/video_player/pubspec.yaml renamed to packages/video_player/video_player/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: video_player
22
description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android and iOS.
44
author: Flutter Team <[email protected]>
5-
version: 0.10.3+1
6-
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player
5+
version: 0.10.3+2
6+
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
77

88
flutter:
99
plugin:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:ui';
7+
8+
import 'package:flutter/services.dart';
9+
import 'package:flutter/widgets.dart';
10+
11+
import 'video_player_platform_interface.dart';
12+
13+
const MethodChannel _channel = MethodChannel('flutter.io/videoPlayer');
14+
15+
/// An implementation of [VideoPlayerPlatform] that uses method channels.
16+
class MethodChannelVideoPlayer extends VideoPlayerPlatform {
17+
@override
18+
Future<void> init() {
19+
return _channel.invokeMethod<void>('init');
20+
}
21+
22+
@override
23+
Future<void> dispose(int textureId) {
24+
return _channel.invokeMethod<void>(
25+
'dispose',
26+
<String, dynamic>{'textureId': textureId},
27+
);
28+
}
29+
30+
@override
31+
Future<int> create(DataSource dataSource) async {
32+
Map<String, dynamic> dataSourceDescription;
33+
34+
switch (dataSource.sourceType) {
35+
case DataSourceType.asset:
36+
dataSourceDescription = <String, dynamic>{
37+
'asset': dataSource.asset,
38+
'package': dataSource.package,
39+
};
40+
break;
41+
case DataSourceType.network:
42+
dataSourceDescription = <String, dynamic>{
43+
'uri': dataSource.uri,
44+
'formatHint': _videoFormatStringMap[dataSource.formatHint]
45+
};
46+
break;
47+
case DataSourceType.file:
48+
dataSourceDescription = <String, dynamic>{'uri': dataSource.uri};
49+
break;
50+
}
51+
52+
final Map<String, dynamic> response =
53+
await _channel.invokeMapMethod<String, dynamic>(
54+
'create',
55+
dataSourceDescription,
56+
);
57+
return response['textureId'];
58+
}
59+
60+
@override
61+
Future<void> setLooping(int textureId, bool looping) {
62+
return _channel.invokeMethod<void>(
63+
'setLooping',
64+
<String, dynamic>{
65+
'textureId': textureId,
66+
'looping': looping,
67+
},
68+
);
69+
}
70+
71+
@override
72+
Future<void> play(int textureId) {
73+
return _channel.invokeMethod<void>(
74+
'play',
75+
<String, dynamic>{'textureId': textureId},
76+
);
77+
}
78+
79+
@override
80+
Future<void> pause(int textureId) {
81+
return _channel.invokeMethod<void>(
82+
'pause',
83+
<String, dynamic>{'textureId': textureId},
84+
);
85+
}
86+
87+
@override
88+
Future<void> setVolume(int textureId, double volume) {
89+
return _channel.invokeMethod<void>(
90+
'setVolume',
91+
<String, dynamic>{
92+
'textureId': textureId,
93+
'volume': volume,
94+
},
95+
);
96+
}
97+
98+
@override
99+
Future<void> seekTo(int textureId, Duration position) {
100+
return _channel.invokeMethod<void>(
101+
'seekTo',
102+
<String, dynamic>{
103+
'textureId': textureId,
104+
'location': position.inMilliseconds,
105+
},
106+
);
107+
}
108+
109+
@override
110+
Future<Duration> getPosition(int textureId) async {
111+
return Duration(
112+
milliseconds: await _channel.invokeMethod<int>(
113+
'position',
114+
<String, dynamic>{'textureId': textureId},
115+
),
116+
);
117+
}
118+
119+
@override
120+
Stream<VideoEvent> videoEventsFor(int textureId) {
121+
return _eventChannelFor(textureId)
122+
.receiveBroadcastStream()
123+
.map((dynamic event) {
124+
final Map<dynamic, dynamic> map = event;
125+
switch (map['event']) {
126+
case 'initialized':
127+
return VideoEvent(
128+
eventType: VideoEventType.initialized,
129+
duration: Duration(milliseconds: map['duration']),
130+
size: Size(map['width']?.toDouble() ?? 0.0,
131+
map['height']?.toDouble() ?? 0.0),
132+
);
133+
case 'completed':
134+
return VideoEvent(
135+
eventType: VideoEventType.completed,
136+
);
137+
case 'bufferingUpdate':
138+
final List<dynamic> values = map['values'];
139+
140+
return VideoEvent(
141+
buffered: values.map<DurationRange>(_toDurationRange).toList(),
142+
eventType: VideoEventType.completed,
143+
);
144+
case 'bufferingStart':
145+
return VideoEvent(eventType: VideoEventType.bufferingStart);
146+
case 'bufferingEnd':
147+
return VideoEvent(eventType: VideoEventType.bufferingEnd);
148+
default:
149+
return VideoEvent(eventType: VideoEventType.unknown);
150+
}
151+
});
152+
}
153+
154+
@override
155+
Widget buildView(int textureId) {
156+
return Texture(textureId: textureId);
157+
}
158+
159+
EventChannel _eventChannelFor(int textureId) {
160+
return EventChannel('flutter.io/videoPlayer/videoEvents$textureId');
161+
}
162+
163+
static const Map<VideoFormat, String> _videoFormatStringMap =
164+
<VideoFormat, String>{
165+
VideoFormat.ss: 'ss',
166+
VideoFormat.hls: 'hls',
167+
VideoFormat.dash: 'dash',
168+
VideoFormat.other: 'other',
169+
};
170+
171+
DurationRange _toDurationRange(dynamic value) {
172+
final List<dynamic> pair = value;
173+
return DurationRange(
174+
Duration(milliseconds: pair[0]),
175+
Duration(milliseconds: pair[1]),
176+
);
177+
}
178+
}

0 commit comments

Comments
 (0)