Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Update video_player
  • Loading branch information
stuartmorgan-g committed May 23, 2025
commit 95ce89123785e8eba5f41fae14d33668070fb662
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ void main() {
});

testWidgets('initializes at the start', (_) async {
final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: _videoAssetKey,
)))!;
final int playerId =
(await player.create(
DataSource(sourceType: DataSourceType.asset, asset: _videoAssetKey),
))!;

expect(
await _getDuration(player, playerId),
Expand All @@ -57,10 +57,10 @@ void main() {
});

testWidgets('can be played', (WidgetTester tester) async {
final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: _videoAssetKey,
)))!;
final int playerId =
(await player.create(
DataSource(sourceType: DataSourceType.asset, asset: _videoAssetKey),
))!;

await player.play(playerId);
await tester.pumpAndSettle(_playDuration);
Expand All @@ -70,10 +70,10 @@ void main() {
});

testWidgets('can seek', (WidgetTester tester) async {
final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: _videoAssetKey,
)))!;
final int playerId =
(await player.create(
DataSource(sourceType: DataSourceType.asset, asset: _videoAssetKey),
))!;

await player.seekTo(playerId, const Duration(seconds: 3));
await tester.pumpAndSettle(_playDuration);
Expand All @@ -86,10 +86,10 @@ void main() {
});

testWidgets('can pause', (WidgetTester tester) async {
final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.asset,
asset: _videoAssetKey,
)))!;
final int playerId =
(await player.create(
DataSource(sourceType: DataSourceType.asset, asset: _videoAssetKey),
))!;

await player.play(playerId);
await tester.pumpAndSettle(_playDuration);
Expand All @@ -112,10 +112,10 @@ void main() {
),
);

final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.file,
uri: file.path,
)))!;
final int playerId =
(await player.create(
DataSource(sourceType: DataSourceType.file, uri: file.path),
))!;

await player.play(playerId);
await tester.pumpAndSettle(_playDuration);
Expand All @@ -126,10 +126,13 @@ void main() {
});

testWidgets('can play a video from network', (WidgetTester tester) async {
final int playerId = (await player.create(DataSource(
sourceType: DataSourceType.network,
uri: getUrlForAssetAsNetworkSource(_videoAssetKey),
)))!;
final int playerId =
(await player.create(
DataSource(
sourceType: DataSourceType.network,
uri: getUrlForAssetAsNetworkSource(_videoAssetKey),
),
))!;

await player.play(playerId);
await player.seekTo(playerId, const Duration(seconds: 5));
Expand All @@ -146,24 +149,27 @@ void main() {
});
}

Future<Duration> _getDuration(
AndroidVideoPlayer player,
int playerId,
) {
return player.videoEventsFor(playerId).firstWhere((VideoEvent event) {
return event.eventType == VideoEventType.initialized;
}).then((VideoEvent event) {
return event.duration!;
});
Future<Duration> _getDuration(AndroidVideoPlayer player, int playerId) {
return player
.videoEventsFor(playerId)
.firstWhere((VideoEvent event) {
return event.eventType == VideoEventType.initialized;
})
.then((VideoEvent event) {
return event.duration!;
});
}

Future<DurationRange> _getBufferingRange(
AndroidVideoPlayer player,
int playerId,
) {
return player.videoEventsFor(playerId).firstWhere((VideoEvent event) {
return event.eventType == VideoEventType.bufferingUpdate;
}).then((VideoEvent event) {
return event.buffered!.first;
});
return player
.videoEventsFor(playerId)
.firstWhere((VideoEvent event) {
return event.eventType == VideoEventType.bufferingUpdate;
})
.then((VideoEvent event) {
return event.buffered!.first;
});
}
67 changes: 24 additions & 43 deletions packages/video_player/video_player_android/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import 'package:video_player_platform_interface/video_player_platform_interface.
import 'mini_controller.dart';

void main() {
runApp(
MaterialApp(
home: _App(),
),
);
runApp(MaterialApp(home: _App()));
}

class _App extends StatelessWidget {
Expand All @@ -38,15 +34,15 @@ class _App extends StatelessWidget {
body: TabBarView(
children: <Widget>[
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_BumbleBeeRemoteVideo(viewType),
builder:
(VideoViewType viewType) => _BumbleBeeRemoteVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) => _RtspRemoteVideo(viewType),
),
_ViewTypeTabBar(
builder: (VideoViewType viewType) =>
_ButterFlyAssetVideo(viewType),
builder:
(VideoViewType viewType) => _ButterFlyAssetVideo(viewType),
),
],
),
Expand All @@ -56,9 +52,7 @@ class _App extends StatelessWidget {
}

class _ViewTypeTabBar extends StatefulWidget {
const _ViewTypeTabBar({
required this.builder,
});
const _ViewTypeTabBar({required this.builder});

final Widget Function(VideoViewType) builder;

Expand Down Expand Up @@ -90,14 +84,8 @@ class _ViewTypeTabBarState extends State<_ViewTypeTabBar>
controller: _tabController,
isScrollable: true,
tabs: const <Widget>[
Tab(
icon: Icon(Icons.texture),
text: 'Texture view',
),
Tab(
icon: Icon(Icons.construction),
text: 'Platform view',
),
Tab(icon: Icon(Icons.texture), text: 'Texture view'),
Tab(icon: Icon(Icons.construction), text: 'Platform view'),
],
),
Expanded(
Expand Down Expand Up @@ -151,9 +139,7 @@ class _ButterFlyAssetVideoState extends State<_ButterFlyAssetVideo> {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(top: 20.0),
),
Container(padding: const EdgeInsets.only(top: 20.0)),
const Text('With assets mp4'),
Container(
padding: const EdgeInsets.all(20),
Expand Down Expand Up @@ -258,10 +244,7 @@ class _RtspRemoteVideoState extends State<_RtspRemoteVideo> {
}

setState(() {
_controller = MiniController.network(
url,
viewType: widget.viewType,
);
_controller = MiniController.network(url, viewType: widget.viewType);
});

_controller!.addListener(() {
Expand Down Expand Up @@ -348,20 +331,21 @@ class _ControlsOverlay extends StatelessWidget {
AnimatedSwitcher(
duration: const Duration(milliseconds: 50),
reverseDuration: const Duration(milliseconds: 200),
child: controller.value.isPlaying
? const SizedBox.shrink()
: const ColoredBox(
color: Colors.black26,
child: Center(
child: Icon(
key: ValueKey<String>('Play'),
Icons.play_arrow,
color: Colors.white,
size: 100.0,
semanticLabel: 'Play',
child:
controller.value.isPlaying
? const SizedBox.shrink()
: const ColoredBox(
color: Colors.black26,
child: Center(
child: Icon(
key: ValueKey<String>('Play'),
Icons.play_arrow,
color: Colors.white,
size: 100.0,
semanticLabel: 'Play',
),
),
),
),
),
GestureDetector(
onTap: () {
Expand All @@ -379,10 +363,7 @@ class _ControlsOverlay extends StatelessWidget {
itemBuilder: (BuildContext context) {
return <PopupMenuItem<double>>[
for (final double speed in _examplePlaybackRates)
PopupMenuItem<double>(
value: speed,
child: Text('${speed}x'),
)
PopupMenuItem<double>(value: speed, child: Text('${speed}x')),
];
},
child: Padding(
Expand Down
Loading