-
Notifications
You must be signed in to change notification settings - Fork 210
feat: ✨ Add web platform support for audio player #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/add-web-support
Are you sure you want to change the base?
feat: ✨ Add web platform support for audio player #472
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive web platform support for the audio_waveforms Flutter plugin, enabling audio playback functionality in web browsers using HTML5 Audio API. The implementation provides feature parity with native platforms for audio playback, while explicitly excluding recording functionality which is not supported on the web platform.
Changes:
- Added web platform implementation for audio player with HTML5 audio elements
- Implemented platform-specific method channel handlers for web
- Added web configuration files and assets for the example app
- Updated dependencies to support web platform (flutter_web_plugins, web package)
Reviewed changes
Copilot reviewed 12 out of 17 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| pubspec.yaml | Added flutter_web_plugins and web dependencies, registered web plugin |
| lib/audio_waveforms_web.dart | Entry point that delegates to web plugin implementation |
| lib/web/audio_waveforms_plugin_web.dart | Main web plugin class handling method channel calls |
| lib/web/audio_player_web.dart | Core audio player implementation using HTMLAudioElement |
| lib/web/waveform_extractor_web.dart | Placeholder waveform extraction with dummy data |
| lib/web/base/constants_web.dart | Web-specific constants |
| lib/web/base/utils_web.dart | Web console logging utilities |
| example/lib/main.dart | Added web platform checks and recording restrictions |
| example/pubspec.yaml | Updated file_picker dependency version |
| example/web/* | Standard Flutter web assets (manifest, index.html, icons, favicon) |
| CHANGELOG.md | Added entry for web platform support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6a79e1d to
2a617d4
Compare
2a617d4 to
8915752
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 12 out of 17 changed files in this pull request and generated 13 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8915752 to
14f26d7
Compare
14f26d7 to
57e662e
Compare
| } | ||
|
|
||
| /// Prepares the audio player with the given path | ||
| Future<bool> preparePlayer(Map<dynamic, dynamic> arguments) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant we pass <String, dynamic>?
| final String path = rawPath; | ||
| final int frequency = arguments[Constants.updateFrequency] ?? | ||
| WebConstants.defaultUpdateFrequency; | ||
| final double? volume = arguments[Constants.volume]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check type here as well
| final completer = Completer<bool>(); | ||
| bool isCompleted = false; | ||
|
|
||
| audioElement.addEventListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to remove listeners?
| return await completer.future | ||
| .timeout( | ||
| const Duration(seconds: WebConstants.defaultLoadTimeout), | ||
| onTimeout: () => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we must not use these type of static timeouts
|
|
||
| // Stop the player if it's currently playing | ||
| if (isPlaying) { | ||
| await stopPlayer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method does same thing as below
| void _sendDurationUpdate(int currentTime) { | ||
| onDurationUpdate(currentTime); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can directly use the callback
| void _sendCompletionEvent() { | ||
| onCompletion(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^
|
|
||
| /// Handles method calls from the platform interface | ||
| Future<dynamic> handleMethodCall(MethodCall call) async { | ||
| final args = call.arguments as Map<dynamic, dynamic>?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use <string, dynamic>
| { | ||
| Constants.playerKey: playerKey, | ||
| Constants.finishType: | ||
| 2, // 2 = stopped (default finish mode on web) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add todo
|
|
||
| import 'package:web/web.dart'; | ||
|
|
||
| extension WebConsoleLogger on String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add top level documentation
Description
This PR introduces comprehensive web platform support to the
audio_waveformsFlutter plugin, enabling audio playback in web applications. The implementation leverages the Web Audio API and HTML5 audio elements to provide feature parity with native platforms.Checklist
fix:,feat:,docs:etc).docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues