Autoplay page narration after a three-second delay
This commit is contained in:
@@ -26,9 +26,9 @@ All app-created text uses the bundled Dancing Script handwriting font, including
|
||||
|
||||
Campaign discoveries now support optional watercolour keepsakes declared in the campaign data. All twelve discoveries have illustrations, and the opening match memory uses the same match watercolour. Each object’s artwork appears only on its discovery leaf after its own pattern is solved. Entry pages, the earlier repair note and the closing leaf never display discovery art, even with completed progress. Pixel pictures are also hidden until solved and remain the fallback for missing artwork.
|
||||
|
||||
Twenty-eight fixed, pre-rendered synthetic recordings play from bundled PCM16 WAV files. Twenty-four readings include the expanded story; the original PCM takes are preserved, followed by the added narrator passages. A single Play control covers the whole page and highlighting follows both parts. Mara’s five original British-English diary takes are preserved; twenty-three guiding passages use a distinct narrator voice, covering the cottage entries/memories/closing leaf and the later campaign introductions and discoveries. All recordings are opt-in, labelled by speaker and support pause/resume, stop, replay, speed and passage highlighting. Page turns and backgrounding stop playback. WAV avoids the Huawei API 26 FLAC playback issue; archival FLACs stay out of the APK. There is no Android reader, runtime synthesis or audio download. See [narration provenance](assets/narration/README.md).
|
||||
Twenty-eight fixed, pre-rendered synthetic recordings play from bundled PCM16 WAV files. Twenty-four readings include the expanded story; the original PCM takes are preserved, followed by the added narrator passages. A single Play control covers the whole page and highlighting follows both parts. Mara’s five original British-English diary takes are preserved; twenty-three guiding passages use a distinct narrator voice, covering the cottage entries/memories/closing leaf and the later campaign introductions and discoveries. Readings start automatically 3 seconds after opening a narrated page, are labelled by speaker and support pause/resume, stop, replay, speed and passage highlighting. Page turns and backgrounding stop playback. WAV avoids the Huawei API 26 FLAC playback issue; archival FLACs stay out of the APK. There is no Android reader, runtime synthesis or audio download. See [narration provenance](assets/narration/README.md).
|
||||
|
||||
Four bundled, original sound textures accompany the story: air around the cottage, harbour water, the stream under the bridge and wind around the lighthouse. They loop quietly, fade when locations change and duck beneath narration. Sound & atmosphere offers a saved mute switch and independent atmosphere volume. Leaving the story or backgrounding the app stops them; readings never start automatically. These are procedurally rendered soundscapes, not field recordings. See [soundscape provenance](assets/audio/AMBIENCE.md).
|
||||
Four bundled, original sound textures accompany the story: air around the cottage, harbour water, the stream under the bridge and wind around the lighthouse. They loop quietly, fade when locations change and duck beneath narration. Sound & atmosphere offers a saved mute switch and independent atmosphere volume. Leaving the story or backgrounding the app stops them; readings start after a 3-second pause on narrated pages. These are procedurally rendered soundscapes, not field recordings. See [soundscape provenance](assets/audio/AMBIENCE.md).
|
||||
|
||||
## Build and run
|
||||
|
||||
@@ -76,7 +76,7 @@ flutter drive --driver test_driver/integration_test.dart \
|
||||
--dart-define=QA_TEST=true -d YOUR_ANDROID_DEVICE
|
||||
```
|
||||
|
||||
The thirty-one unit/widget tests cover 40 Java reference boards (including signed 64-bit seeds), 300 graded generated boards, solver counts against 300 exhaustive small systems, all twelve campaign solutions, bounded campaign comparison chains, solved-grid inspection after restart, discovery animation/replay, repeated free story hints, streaks, fresh progress, read-ahead, completion awards, campaign read-ahead restoration, gesture isolation, swipes over text and blank paper, cancelled drags, vertical scrolling, landscape and larger text; it also checks every cottage leaf with the real font at 1.5× text, all four hint controls, legacy route migration and exactly-once completion after restart. Reference parity protects the port’s rules; it is not used to migrate saves.
|
||||
The thirty-five unit/widget tests cover 40 Java reference boards (including signed 64-bit seeds), 300 graded generated boards, solver counts against 300 exhaustive small systems, all twelve campaign solutions, bounded campaign comparison chains, solved-grid inspection after restart, discovery animation/replay, repeated free story hints, streaks, fresh progress, read-ahead, completion awards, campaign read-ahead restoration, gesture isolation, swipes over text and blank paper, cancelled drags, vertical scrolling, landscape and larger text; it also checks every cottage leaf with the real font at 1.5× text, all four hint controls, legacy route migration and exactly-once completion after restart. Reference parity protects the port’s rules; it is not used to migrate saves.
|
||||
|
||||
The physical-device integration test uses a disposable in-memory game plus an isolated QA disk round-trip. It plays all five real WAV files, checks pause/resume, explores the six leaves, verifies bookmarks/discoveries, solves match and lantern puzzles and checks exactly-once awards. Screenshots are saved in `artifacts/flutter-check/`. The release smoke script requires an active, unmuted 24 kHz media track in the tablet’s audio mixer as well as exercising the actual play/pause/resume UI and restores the last page after process restart, without injecting puzzle fixtures. The release build includes a targeted R8 keep rule for the database constructor used reflectively by AdMob’s WorkManager dependency. Advertising is disabled for the automated story tests; real UMP startup is checked separately in the normal build. Reward delivery, cancellation and ad no-fill still need manual release testing with your final AdMob configuration.
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ Every diary entry pairs a short passage with a small original illustration and a
|
||||
- Review the warm, unhurried delivery before expanding production. Consider a recorded actor performance for Mara; keep synthetic prototype recordings clearly identified in the asset provenance.
|
||||
- Record a narrator’s voice for the present-day narration: the welcome, chapter openings and transitions. Use one consistent, warm narrator, keep that voice distinct from Mara’s first-person diary readings and the grandchild’s annotations, and script every line before the recording session.
|
||||
- Distinguish Mara’s first-person diary entries from present-day narration and the grandchild’s annotations. Make the speaker clear in the writing and listen control.
|
||||
- Offer play, pause, exact-position resume, stop and replay. Keep narration opt-in, without autoplay on page entry.
|
||||
- Offer play, pause, exact-position resume, stop and replay. Start narration 3 seconds after opening a narrated page, as requested for device playtesting. Manual playback, pause or stop cancels the pending start.
|
||||
- Highlight the current passage using timing cues while keeping all text accessible.
|
||||
- Stop playback when a page is turned or the app backgrounds; pause on audio interruption. Never overlap recordings.
|
||||
- Keep reading available if an asset cannot be played. Audio requires no download, game backend or per-listen server call.
|
||||
|
||||
@@ -16,4 +16,4 @@ python scripts/render_ambience.py
|
||||
python3 scripts/check_soundscape_assets.py
|
||||
```
|
||||
|
||||
The app plays bundled files, with no synthesis at runtime. Atmosphere defaults on inside the story. Sound & atmosphere saves a separate mute switch and volume, independent of the narration controls. Scene changes fade over 240 ms. The atmosphere falls to a quarter of its usual gain under narration. Muting, leaving the story or backgrounding stops it; foregrounding restores only environmental audio. Narration remains opt-in. Audio interruptions and headphone removal pause the players.
|
||||
The app plays bundled files, with no synthesis at runtime. Atmosphere defaults on inside the story. Sound & atmosphere saves a separate mute switch and volume, independent of the narration controls. Scene changes fade over 240 ms. The atmosphere falls to a quarter of its usual gain under narration. Muting, leaving the story or backgrounding stops it; foregrounding restores only environmental audio. Narration starts 3 seconds after opening a narrated page; manual controls cancel the delayed start. Audio interruptions and headphone removal pause the players.
|
||||
|
||||
@@ -9,7 +9,7 @@ Twenty-eight fixed recordings accompany the story. Mara’s five original diary
|
||||
- `assets/audio/narration_*.flac`: archival lossless exports, excluded from the APK.
|
||||
- `licenses/`: Kokoro ONNX wrapper MIT and model Apache 2.0 licenses.
|
||||
|
||||
Mara uses generation speed 0.82 and the narrator 0.88, with short fades, paragraph pauses and peak normalization. The in-app speed control changes playback speed without changing pitch. Pausing preserves the actual recording position; leaving a page releases playback. Readings never autoplay on entry.
|
||||
Mara uses generation speed 0.82 and the narrator 0.88, with short fades, paragraph pauses and peak normalization. The in-app speed control changes playback speed without changing pitch. Pausing preserves the actual recording position; leaving a page releases playback. Readings autoplay 3 seconds after opening a narrated page. Page turns, backgrounding, Play, Pause and Stop cancel the pending start. Folded notes wait until unfolded.
|
||||
|
||||
## Regeneration
|
||||
|
||||
@@ -34,4 +34,4 @@ A future actor recording can replace the masters and bundled assets while preser
|
||||
Playback uses PCM WAV because the connected Huawei API 26 tablet advanced the FLAC clock without creating an AudioTrack. WAV produces an active, unmuted 24 kHz mono PCM media track through the speaker, and the user confirmed audible speech. The release smoke test now checks that mixer track, in addition to pause/resume and elapsed time.
|
||||
|
||||
|
||||
The seven cottage narrator recordings cover the lantern/key/compass entries and memories and the closing threshold leaf. Sixteen more cover the before/after passages for campaign levels 4–11. Puzzle instruction leaves remain unvoiced. On-screen labels distinguish “Mara · diary reading” from “Narrator · recorded story”; playback is opt-in and stops on navigation or backgrounding. Cue highlighting follows both displayed passages. One Play/Pause/Resume/Replay control covers the whole page, and the speaker label follows per-cue voice changes. Original PCM-prefix hashes are checked alongside full-track checksums.
|
||||
The seven cottage narrator recordings cover the lantern/key/compass entries and memories and the closing threshold leaf. Sixteen more cover the before/after passages for campaign levels 4–11. Puzzle instruction leaves remain unvoiced. On-screen labels distinguish “Mara · diary reading” from “Narrator · recorded story”; playback starts after a 3-second page delay and stops on navigation or backgrounding. Cue highlighting follows both displayed passages. One Play/Pause/Resume/Replay control covers the whole page, and the speaker label follows per-cue voice changes. Original PCM-prefix hashes are checked alongside full-track checksums.
|
||||
|
||||
+4
-1
@@ -337,6 +337,7 @@ Board key formats (`<key>`):
|
||||
|
||||
### Audio flow
|
||||
|
||||
- `Narrator.scheduleAutoplay(id, speed)` owns one 3-second timer. `_scheduleAutoplay()` in the notebook calls it on initial entry, page changes and unfolding a note. Only story/briefing/reveal screens with a bundled track qualify; folded notes and puzzles are silent. Manual play/pause/stop, leaving the page, backgrounding and disposal cancel the timer. Returning from the background does not restart a paused/stopped reading. Sound settings cancel a pending start too.
|
||||
- `Narrator` wraps one `AudioPlayer` plus `audio_session` (speech configuration). `toggle(id, speed)` loads the track, seeks when finished, sets speed and plays; `pause`/`stop` are idempotent.
|
||||
- `label`, `status` and `passage` drive the `audio()` row; `passage` is highlighted inside the leaf text by `reading(text)` using cue timings.
|
||||
- Narration stops on route change and when the app backgrounds; the player is disposed with `Notebook`.
|
||||
@@ -345,7 +346,7 @@ Board key formats (`<key>`):
|
||||
### Environmental audio
|
||||
|
||||
- `Ambience` owns a separate looping player. `soundscapeFor(index)` maps cottage/home to cottage air, boat/anchor/bell to harbour water, bridge to flowing water and tower discoveries to wind. Home, contents, daily and practice screens are silent.
|
||||
- `_syncAtmosphere()` follows navigation, narration and app lifecycle. Story ambience defaults on and resumes on foregrounding; narration stays opt-in. Muting/backgrounding stops it; scene transitions and volume changes fade over 240 ms.
|
||||
- `_syncAtmosphere()` follows navigation, narration and app lifecycle. Story ambience defaults on and resumes on foregrounding; narration starts 3 seconds after opening a narrated page. Muting/backgrounding stops it; scene transitions and volume changes fade over 240 ms.
|
||||
- Environmental gain is `0.4 × saved volume`, reduced to one quarter while narration plays or loads. Both players share the speech audio session; the environmental player disables automatic session activation to avoid competing with narration. Audio interruptions/headphone removal use just_audio interruption handling.
|
||||
- A serial queue and revision guard discard stale requests while loading/fading. Missing soundscapes never block narration or puzzles. `AmbienceOutput` allows race, fade, failure and lifecycle tests without a device backend.
|
||||
- `scripts/render_ambience.py` deterministically renders four original 24-second PCM16/24 kHz loops offline. `assets/audio/ambience_manifest.json` records seeds/checksums. `scripts/check_soundscape_assets.py` checks bundling, PCM format, levels and loop boundaries.
|
||||
@@ -363,6 +364,8 @@ Board key formats (`<key>`):
|
||||
|
||||
| File | Covers |
|
||||
| --- | --- |
|
||||
| `test/narration_autoplay_test.dart` | Exact 3-second delay, one start per visit, cancellation/replacement, recorded-page eligibility, unfolding notes and backgrounding |
|
||||
| `integration_test/autoplay_test.dart` | Real-device delayed playback of bundled WAVs, cancellation when entering a puzzle and Stop preventing restart |
|
||||
| `test/ambience_test.dart` | Scene mapping, voice ducking, mute/background stop, stale loading requests, backend failure/recovery and disposal |
|
||||
| `integration_test/soundscape_test.dart` | Real-device decoding of all 24 new continuations, bridge/narration mixing, saved mute and automatic Mara-to-narrator handoff |
|
||||
| `test/puzzle_test.dart` | 40 Java reference boards (signed 64-bit seeds), 300 graded boards, solver counts vs. exhaustive search, campaign uniqueness/no-guess, streaks, fresh progress, read-ahead, daily awards and practice levels |
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/main.dart';
|
||||
import 'package:lumen/services/narrator.dart';
|
||||
import 'package:lumen/services/progress.dart';
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
testWidgets(
|
||||
'real recordings autoplay after three seconds and page turns cancel them',
|
||||
(tester) async {
|
||||
expect(const bool.fromEnvironment('QA_TEST'), true);
|
||||
final book = await Book.load();
|
||||
final voice = Narrator(book.tracks);
|
||||
final game = Game(book, Progress.memory())..showStory(0);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Notebook(game: game, adsEnabled: false, narrator: voice),
|
||||
),
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 2300));
|
||||
await tester.pump();
|
||||
expect(voice.playing, false);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 1800));
|
||||
await tester.pump();
|
||||
expect(voice.page, 'cottage.dedication');
|
||||
expect(voice.playing, true);
|
||||
expect(voice.error, isEmpty);
|
||||
game.showStory(1);
|
||||
await tester.pump();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 600));
|
||||
game.showStory(2);
|
||||
await tester.pump();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 3500));
|
||||
expect(voice.playing, false);
|
||||
expect(voice.page, isEmpty);
|
||||
game.showStory(1);
|
||||
await tester.pump();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 4100));
|
||||
expect(voice.playing, true);
|
||||
expect(voice.page, 'cottage.window');
|
||||
await voice.stop();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 3500));
|
||||
expect(voice.playing, false);
|
||||
expect(voice.autoplayPending, false);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pumpAndSettle();
|
||||
},
|
||||
);
|
||||
}
|
||||
+29
-4
@@ -64,9 +64,15 @@ class LumenApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
class Notebook extends StatefulWidget {
|
||||
const Notebook({super.key, required this.game, required this.adsEnabled});
|
||||
const Notebook({
|
||||
super.key,
|
||||
required this.game,
|
||||
required this.adsEnabled,
|
||||
this.narrator,
|
||||
});
|
||||
final Game game;
|
||||
final bool adsEnabled;
|
||||
final Narrator? narrator;
|
||||
@override
|
||||
State<Notebook> createState() => _NotebookState();
|
||||
}
|
||||
@@ -84,7 +90,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
narrator = Narrator(g.book.tracks);
|
||||
narrator = widget.narrator ?? Narrator(g.book.tracks);
|
||||
ambience = Ambience();
|
||||
narrator.addListener(_syncAtmosphere);
|
||||
ads = Ads(enabled: widget.adsEnabled);
|
||||
@@ -94,6 +100,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
unawaited(ads.start());
|
||||
_syncAtmosphere();
|
||||
if (mounted) _scheduleAutoplay();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -101,6 +108,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
if (_route != route) {
|
||||
_route = route;
|
||||
unawaited(narrator.stop());
|
||||
_scheduleAutoplay();
|
||||
}
|
||||
_syncAtmosphere();
|
||||
if (mounted) setState(() {});
|
||||
@@ -109,6 +117,19 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
bool get atmosphereEnabled =>
|
||||
!prefs.contains('ambience_enabled') || prefs.flag('ambience_enabled');
|
||||
|
||||
void _scheduleAutoplay() {
|
||||
final recordedPage =
|
||||
_foreground &&
|
||||
[Screen.story, Screen.briefing, Screen.reveal].contains(g.screen) &&
|
||||
!(g.screen == Screen.story &&
|
||||
g.storyPage.type == StoryPageType.note &&
|
||||
!prefs.flag('notebook_note_open'));
|
||||
narrator.scheduleAutoplay(
|
||||
recordedPage ? recordingId : null,
|
||||
prefs.decimal('recording_speed'),
|
||||
);
|
||||
}
|
||||
|
||||
void _syncAtmosphere() {
|
||||
final inStory =
|
||||
g.mode == Mode.campaign &&
|
||||
@@ -738,6 +759,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
|
||||
void openLetter() {
|
||||
unawaited(prefs.set('notebook_note_open', true));
|
||||
_scheduleAutoplay();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -776,7 +798,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> soundSettings() => showDialog<void>(
|
||||
Future<void> soundSettings() {
|
||||
narrator.cancelAutoplay();
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (context, refresh) {
|
||||
@@ -815,7 +839,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
: null,
|
||||
),
|
||||
writing(
|
||||
'Readings play when you press Play. Your device volume controls the voice.',
|
||||
'Readings start 3 seconds after opening a page. You can play, pause or stop them at any time. Your device volume controls the voice.',
|
||||
size: 18,
|
||||
color: muted,
|
||||
),
|
||||
@@ -834,6 +858,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget contents() {
|
||||
final chapter = g.contentsChapter;
|
||||
|
||||
@@ -16,6 +16,8 @@ class Narrator extends ChangeNotifier {
|
||||
final List<StreamSubscription<dynamic>> _subscriptions = [];
|
||||
String page = '', error = '';
|
||||
bool loading = false;
|
||||
Timer? _autoplay;
|
||||
bool get autoplayPending => _autoplay?.isActive ?? false;
|
||||
int _generation = 0;
|
||||
bool get playing =>
|
||||
_player.playing && _player.processingState != ProcessingState.completed;
|
||||
@@ -36,7 +38,9 @@ class Narrator extends ChangeNotifier {
|
||||
String get status => error.isNotEmpty
|
||||
? error
|
||||
: page.isEmpty
|
||||
? 'A recorded reading, kept with this page'
|
||||
? autoplayPending
|
||||
? 'The reading starts automatically in 3 seconds'
|
||||
: 'A recorded reading, kept with this page'
|
||||
: finished
|
||||
? 'End of the reading · listen again whenever you like'
|
||||
: '${playing ? 'Playing' : 'Paused'} · ${_time(position)} / ${_time(_player.duration ?? Duration.zero)}';
|
||||
@@ -61,7 +65,26 @@ class Narrator extends ChangeNotifier {
|
||||
return tracks[page]?['speaker'] ?? '';
|
||||
}
|
||||
|
||||
void scheduleAutoplay(String? id, double speed) {
|
||||
cancelAutoplay();
|
||||
if (id == null || !tracks.containsKey(id)) return;
|
||||
_autoplay = Timer(const Duration(seconds: 3), () {
|
||||
_autoplay = null;
|
||||
notifyListeners();
|
||||
if (!playing && !loading) unawaited(toggle(id, speed));
|
||||
});
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void cancelAutoplay() {
|
||||
if (_autoplay == null) return;
|
||||
_autoplay!.cancel();
|
||||
_autoplay = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> toggle(String id, double speed) async {
|
||||
cancelAutoplay();
|
||||
if (loading) return;
|
||||
if (playing && page == id) {
|
||||
await _player.pause();
|
||||
@@ -105,10 +128,12 @@ class Narrator extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> pause() async {
|
||||
cancelAutoplay();
|
||||
await _player.pause();
|
||||
}
|
||||
|
||||
Future<void> stop() async {
|
||||
cancelAutoplay();
|
||||
++_generation;
|
||||
page = '';
|
||||
loading = false;
|
||||
@@ -119,6 +144,7 @@ class Narrator extends ChangeNotifier {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_autoplay?.cancel();
|
||||
for (final s in _subscriptions) {
|
||||
unawaited(s.cancel());
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ def dump():
|
||||
adb('shell','uiautomator','dump','/sdcard/lumen-flutter-smoke.xml')
|
||||
return ET.fromstring(adb('exec-out','cat','/sdcard/lumen-flutter-smoke.xml'))
|
||||
def value(n):return n.get('text','')+' '+n.get('content-desc','')
|
||||
def find(text):
|
||||
def find_any(*texts):
|
||||
root=dump()
|
||||
for text in texts:
|
||||
for n in root.iter('node'):
|
||||
if text.casefold() in value(n).casefold():return n
|
||||
raise AssertionError('Missing '+text+'; screen: '+str([value(n) for n in root.iter('node') if value(n).strip()]))
|
||||
raise AssertionError('Missing '+str(texts)+'; screen: '+str([value(n) for n in root.iter('node') if value(n).strip()]))
|
||||
def find(text):return find_any(text)
|
||||
def tapnode(n):
|
||||
x1,y1,x2,y2=map(int,re.findall(r'\d+',n.get('bounds')));adb('shell','input','tap',str((x1+x2)//2),str((y1+y2)//2))
|
||||
def tap(text):tapnode(find(text))
|
||||
@@ -38,7 +40,9 @@ def swipe_text(text,dx):
|
||||
swipe_text('For you, when you are ready',-360);find('By the cottage window')
|
||||
swipe_text('By the cottage window',360);find('For you, when you are ready')
|
||||
tap('Next leaf');find('By the cottage window')
|
||||
play=find('Play this reading');tapnode(play);time.sleep(2)
|
||||
play=find_any('Pause recording','Play this reading')
|
||||
if 'Pause recording' not in value(play):tapnode(play)
|
||||
time.sleep(2)
|
||||
# A clock can advance even when the decoder creates no audio track. Inspect
|
||||
# the real mixer while playback is active (verified on the API 26 tablet).
|
||||
pid=adb('shell','pidof',a.package).decode().strip().split()[0]
|
||||
@@ -52,7 +56,7 @@ def seconds():
|
||||
first=seconds();assert first>=1
|
||||
tapnode(play);time.sleep(2);tapnode(play);find('Resume recording');assert seconds()>=first+1
|
||||
tap('Stop');find('Play this reading')
|
||||
adb('shell','am','force-stop',a.package);launch();find('By the cottage window');find('Play this reading');shot('main-restored-page.png')
|
||||
adb('shell','am','force-stop',a.package);launch();find('By the cottage window');find_any('Play this reading','Pause recording');shot('main-restored-page.png')
|
||||
tap('Close book')
|
||||
if a.expect_fresh:find('0 / 12');find('0\nPATTERNS FOUND')
|
||||
print('PASS: optimized app launches, swipes over the writing in both directions, plays through its UI, resumes audio and restores the reading place after process restart.')
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/main.dart';
|
||||
import 'package:lumen/services/narrator.dart';
|
||||
import 'package:lumen/services/progress.dart';
|
||||
|
||||
class _Voice extends Narrator {
|
||||
_Voice(super.tracks);
|
||||
final List<(String, double)> starts = [];
|
||||
bool active = false;
|
||||
@override
|
||||
bool get playing => active;
|
||||
@override
|
||||
Future<void> toggle(String id, double speed) async {
|
||||
cancelAutoplay();
|
||||
page = id;
|
||||
active = !active;
|
||||
starts.add((id, speed));
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pause() async {
|
||||
active = false;
|
||||
await super.pause();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stop() async {
|
||||
active = false;
|
||||
await super.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('autoplay waits exactly three seconds and starts only once', (
|
||||
tester,
|
||||
) async {
|
||||
final voice = _Voice({'first': {}, 'second': {}});
|
||||
voice.scheduleAutoplay('first', 1.15);
|
||||
await tester.pump(const Duration(milliseconds: 2999));
|
||||
expect(voice.starts, isEmpty);
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(voice.starts, [('first', 1.15)]);
|
||||
await tester.pump(const Duration(seconds: 10));
|
||||
expect(voice.starts.length, 1);
|
||||
await voice.stop();
|
||||
voice.scheduleAutoplay('first', 1);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
voice.scheduleAutoplay('second', .85);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(voice.starts.length, 1);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(voice.starts.last, ('second', .85));
|
||||
voice.dispose();
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'manual playback, pause, stop and disposal cancel pending autoplay',
|
||||
(tester) async {
|
||||
final voice = _Voice({'page': {}});
|
||||
voice.scheduleAutoplay('page', 1);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
await voice.toggle('page', 1);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
await voice.stop();
|
||||
voice.scheduleAutoplay('page', 1);
|
||||
await voice.pause();
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
voice.scheduleAutoplay('page', 1);
|
||||
await voice.stop();
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
voice.scheduleAutoplay('page', 1);
|
||||
voice.dispose();
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'page changes cancel old readings and folded notes wait until opened',
|
||||
(tester) async {
|
||||
final book = (await tester.runAsync(Book.load))!;
|
||||
final voice = _Voice(book.tracks);
|
||||
final g = Game(book, Progress.memory({'story_access_level': 11}));
|
||||
g.showStory(0);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Notebook(game: g, adsEnabled: false, narrator: voice),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
g.showStory(1);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(voice.starts, isEmpty);
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(voice.starts.single.$1, 'cottage.window');
|
||||
g.showStory(2);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
g.showStory(4);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, 1);
|
||||
await tester.ensureVisible(find.text('Unfold Gran’s note'));
|
||||
await tester.tap(find.text('Unfold Gran’s note'));
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(voice.starts.last.$1, 'cottage.folded.note');
|
||||
g.briefing(4);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(voice.starts.last.$1, 'campaign.4.before');
|
||||
g.reveal(4, readAhead: true);
|
||||
await tester.pump(const Duration(seconds: 3));
|
||||
expect(voice.starts.last.$1, 'campaign.4.after');
|
||||
final count = voice.starts.length;
|
||||
g.home();
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts.length, count);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('backgrounding cancels a delayed reading', (tester) async {
|
||||
final book = (await tester.runAsync(Book.load))!;
|
||||
final voice = _Voice(book.tracks);
|
||||
final g = Game(book, Progress.memory())..showStory(0);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Notebook(game: g, adsEnabled: false, narrator: voice),
|
||||
),
|
||||
);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
|
||||
await tester.pump(const Duration(seconds: 4));
|
||||
expect(voice.starts, isEmpty);
|
||||
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user