Improves audio player functionality and configuration#2
Conversation
Ensures the configured rewind and fast-forward intervals are correctly used by system media controls. Simplifies the internal playback state stream and prevents redundant emissions for improved efficiency.
There was a problem hiding this comment.
Pull request overview
This PR updates the mt_audio public API and internal streaming to improve playback control behavior and reduce redundant state emissions, while updating docs/examples to match the new API.
Changes:
- Forward
ffRewindIntervalintoAudioServiceConfigso system media controls use the configured seek interval. - Replace
MtAudioSource(andsetSource) with explicitsetAudioItem/setPlaylistAPIs across library + examples/docs. - Simplify playback state stream wiring and apply
.distinct()to reduce redundant emissions.
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pubspec.lock | Updates transitive dependency lockfile entries. |
| lib/src/player/mt_audio_player.dart | Forwards seek intervals into AudioServiceConfig; simplifies playback state stream and adds setAudioItem/setPlaylist. |
| lib/src/models/mt_audio_source.dart | Removes the sealed MtAudioSource model hierarchy (breaking change). |
| lib/src/handler/mt_audio_handler.dart | Adds setItem/setPlaylist; forwards player errors into errorStream; renames Android Auto delegate field. |
| lib/src/carplay/mt_carplay_delegate.dart | Updates documentation snippet to new setAudioItem API. |
| lib/src/android_auto/mt_android_auto_delegate.dart | Updates documentation snippet to new setAudioItem API. |
| lib/mt_audio.dart | Stops exporting removed mt_audio_source.dart. |
| example/pubspec.lock | Updates example lockfile (path package version + transitive lock). |
| example/lib/providers/example_carplay_delegate.dart | Migrates example delegate to setAudioItem / setPlaylist. |
| example/lib/providers/example_android_auto_delegate.dart | Migrates example delegate to setAudioItem. |
| example/lib/pages/queue_page.dart | Migrates example UI to setPlaylist. |
| example/lib/pages/home_page.dart | Migrates example UI to new source-loading methods and renames helper. |
| README.md | Updates package positioning + usage examples to new API and new install version text. |
| CLAUDE.md | Updates internal module notes to reflect the new two-method source API. |
| CHANGELOG.md | Adds a 0.2.0-beta.3 entry describing the breaking changes and fixes. |
| .github/workflows/publish.yml | Expands tag trigger patterns to include prerelease-style tags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ```yaml | ||
| dependencies: | ||
| mt_audio: ^0.2.0-beta.1 | ||
| mt_audio: ^0.2.0-beta.3 |
There was a problem hiding this comment.
README now instructs installing mt_audio: ^0.2.0-beta.3, but pubspec.yaml in this repo still declares version: 0.2.0-beta.2. Either bump the package version (and regenerate locks) or keep the README version aligned with the actual package version to avoid publishing/install confusion.
| ## 0.2.0-beta.3 - 2026-02-16 | ||
|
|
||
| ### Changed | ||
|
|
||
| - Replaced `MtAudioSource` sealed class (`MtSingleSource`, `MtPlaylistSource`, `MtLiveSource`) with two explicit methods on `MtAudioPlayer`: `setAudioItem(MtAudioItem)` and `setPlaylist(List<MtAudioItem>, {int initialIndex})`. | ||
| - Simplified internal playback state stream and added `.distinct()` to prevent redundant emissions. |
There was a problem hiding this comment.
CHANGELOG introduces a 0.2.0-beta.3 entry, but the package pubspec.yaml still declares version: 0.2.0-beta.2. Please align the changelog entry with the actual package version being released (or bump pubspec.yaml accordingly) so tags/publishing and user expectations match.
| - "v[0-9]+.[0-9]+.[0-9]+" | ||
| - "v[0-9]+.[0-9]+.[0-9]+-**" |
There was a problem hiding this comment.
The tag filters here use GitHub Actions glob patterns (not regex). Patterns like "v[0-9]+.[0-9]+.[0-9]+-" treat '+' as a literal character and are unlikely to match normal semver tags (and '' is unnecessary). Consider switching to glob-appropriate patterns (e.g., v[0-9].[0-9].[0-9]- or v*..-*), and likewise updating the non-suffixed tag pattern for consistency.
| - "v[0-9]+.[0-9]+.[0-9]+" | |
| - "v[0-9]+.[0-9]+.[0-9]+-**" | |
| - "v[0-9]*.[0-9]*.[0-9]*" | |
| - "v[0-9]*.[0-9]*.[0-9]*-*" |
| // Forward playback errors to error subject | ||
| _player.errorStream.listen((error) { | ||
| _errorSubject.add( | ||
| MtAudioError( | ||
| code: MtAudioErrorCode.unknown, | ||
| message: error.message ?? 'Playback error', | ||
| details: error.toString(), | ||
| ), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
This new _player.errorStream.listen(...) subscription isn’t stored/cancelled, and dispose() closes _errorSubject before calling _player.dispose(). That creates a race where an error event can arrive during disposal (or before _player.dispose() runs) and attempt _errorSubject.add(...) after the subject is closed, throwing a bad state error. Store the subscription and cancel it in dispose(), or reorder disposal so the player is disposed (or listeners cancelled) before closing the subjects.
Updates the pubspec version to 0.2.0-beta.3 and adjusts the tag matching regular expression in the publish workflow to allow for multi-digit version numbers.
Updates the audio player to improve functionality and configuration options.
.distinct()to prevent redundant emissions, optimizing performance.