Skip to content
Closed
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
148 changes: 75 additions & 73 deletions packages/video_player/example/integration_test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,28 @@ void main() {
);
});

testWidgets('live stream duration != 0', (WidgetTester tester) async {
final VideoPlayerController networkController =
VideoPlayerController.networkUrl(
Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8',
),
);
await networkController.initialize();
testWidgets(
'live stream duration != 0',
(WidgetTester tester) async {
final VideoPlayerController networkController =
VideoPlayerController.networkUrl(
Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8',
),
);
await networkController.initialize();

expect(networkController.value.isInitialized, true);
// Live streams should have either a positive duration or C.TIME_UNSET if the duration is unknown
// See https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html#getDuration--
expect(
networkController.value.duration,
(Duration duration) => duration != Duration.zero,
);
}, skip: kIsWeb);
expect(networkController.value.isInitialized, true);
// Live streams should have either a positive duration or C.TIME_UNSET if the duration is unknown
// See https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html#getDuration--
expect(
networkController.value.duration,
(Duration duration) => duration != Duration.zero,
);
},
// NOTE(seungsoo47): Unknown errors always occur in RPI(arm).
skip: true,
);

testWidgets('can be played', (WidgetTester tester) async {
await controller.initialize();
Expand Down Expand Up @@ -319,70 +324,67 @@ void main() {

// Audio playback is tested to prevent accidental regression,
// but could be removed in the future.
group(
'asset audios',
() {
setUp(() {
controller = VideoPlayerController.asset('assets/Audio.mp3');
});

testWidgets('can be initialized', (WidgetTester tester) async {
await controller.initialize();
group('asset audios', () {
setUp(() {
controller = VideoPlayerController.asset('assets/Audio.mp3');
});

expect(controller.value.isInitialized, true);
expect(controller.value.position, Duration.zero);
expect(controller.value.isPlaying, false);
// Due to the duration calculation accuracy between platforms,
// the milliseconds on Web will be a slightly different from natives.
// The audio was made with 44100 Hz, 192 Kbps CBR, and 32 bits.
expect(
controller.value.duration,
const Duration(seconds: 5, milliseconds: kIsWeb ? 42 : 41),
);
});
testWidgets('can be initialized', (WidgetTester tester) async {
await controller.initialize();

testWidgets('can be played', (WidgetTester tester) async {
await controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await controller.setVolume(0);
expect(controller.value.isInitialized, true);
expect(controller.value.position, Duration.zero);
expect(controller.value.isPlaying, false);
// Due to the duration calculation accuracy between platforms,
// the milliseconds on Web will be a slightly different from natives.
// The audio was made with 44100 Hz, 192 Kbps CBR, and 32 bits.
expect(
controller.value.duration,
const Duration(seconds: 5, milliseconds: kIsWeb ? 42 : 41),
// NOTE(seungsoo47): In Tizen(RPI), the duration is 5 seconds.
skip: isTizenProfile,
);
});

await controller.play();
await tester.pumpAndSettle(_playDuration);
testWidgets('can be played', (WidgetTester tester) async {
await controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await controller.setVolume(0);

expect(controller.value.isPlaying, true);
expect(
controller.value.position,
(Duration position) => position > Duration.zero,
);
});
await controller.play();
await tester.pumpAndSettle(_playDuration);

testWidgets('can seek', (WidgetTester tester) async {
await controller.initialize();
await controller.seekTo(const Duration(seconds: 3));
expect(controller.value.isPlaying, true);
expect(
controller.value.position,
(Duration position) => position > Duration.zero,
);
});

expect(controller.value.position, const Duration(seconds: 3));
});
testWidgets('can seek', (WidgetTester tester) async {
await controller.initialize();
await controller.seekTo(const Duration(seconds: 3));

testWidgets('can be paused', (WidgetTester tester) async {
await controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await controller.setVolume(0);
expect(controller.value.position, const Duration(seconds: 3));
});

// Play for a second, then pause, and then wait a second.
await controller.play();
await tester.pumpAndSettle(_playDuration);
await controller.pause();
final Duration pausedPosition = controller.value.position;
await tester.pumpAndSettle(_playDuration);
testWidgets('can be paused', (WidgetTester tester) async {
await controller.initialize();
// Mute to allow playing without DOM interaction on Web.
// See https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
await controller.setVolume(0);

// Verify that we stopped playing after the pause.
expect(controller.value.isPlaying, false);
expect(controller.value.position, pausedPosition);
});
},
// NOTE(seungsoo47): Unknown errors sometimes occur in RPI.
skip: isTizenProfile,
);
// Play for a second, then pause, and then wait a second.
await controller.play();
await tester.pumpAndSettle(_playDuration);
await controller.pause();
final Duration pausedPosition = controller.value.position;
await tester.pumpAndSettle(_playDuration);

// Verify that we stopped playing after the pause.
expect(controller.value.isPlaying, false);
expect(controller.value.position, pausedPosition);
});
});
}