-
Notifications
You must be signed in to change notification settings - Fork 853
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
feat!: event channel #1352
feat!: event channel #1352
Conversation
...s/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt
Outdated
Show resolved
Hide resolved
...s/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt
Show resolved
Hide resolved
@luanpotter @spydon we could also think about unifying the logger and the error stream and handle the logging on the dart side to gain more control. But don't know if it would hit on performance, but I don't think so... |
@luanpotter @spydon I unified the error and the logs in a single stream, or more specific: a stream for each player and a global stream to log stuff outside of player scope. I just implemented it for Android, but wanted you to review before rewriting the other platforms. Thank you in advance for your feedback. |
Looks like a great improvement to me! I have too little knowledge about any potential downsides to do a proper review, but I'm sure Luan will chime in. |
_onLogStreamSubscription = _onLog.listen(logHandler); | ||
} | ||
|
||
static void setGlobalLogHandler(void Function(Log log)? logHandler) { |
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.
I'm also considering to handle both streams in the Logger
class and then be able to set only one logging handler in there, which would make it easier to handle all logs at once and would allow the preprocessing by the log level. Downside is, that you cannot differentiate between player logs and global logs anymore.
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.
Now I solved it by exposing the log stream (per player and global), but also allow the user to disable logs/errors via Logger.logLevel
. The log level now is not attached to the AudioPlayer anymore, as it can/should handle logs / errors from anywhere (like global ones, too).
…stream # Conflicts: # packages/audioplayers/example/test/logger_test.dart # packages/audioplayers_platform_interface/lib/global_platform_interface.dart # packages/audioplayers_platform_interface/lib/method_channel_audioplayers_platform.dart
I think the work is done now. I tried to split independent changes as Merge Requests beforehand, but this still is a bulky Merge Request. As I'm definitely no expert in C / C++ and Swift, it would be nice if someone can have a look into these. Or if having any concerns elsewhere in these changes. |
@@ -4,6 +4,7 @@ publish_to: none | |||
|
|||
dependencies: | |||
audioplayers: ^3.0.1 | |||
audioplayers_platform_interface: ^4.0.0 |
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.
should the main audioplayers package expose anything that users my want to access? I think no one should have to depend on platform_interface directly
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.
You're right. I decided to test the integration tests of audioplayers_platform_interface
(which weren't present before) alos in the audioplayers
package, to avoid having and maintaining two example apps. So therefore this dependency is listed here (not relevant for the actual example app). But I changed it to a dev dependency now.
@@ -219,10 +223,10 @@ class SoundPoolManager { | |||
.setAudioAttributes(attrs) | |||
.setMaxStreams(maxStreams) | |||
.build() | |||
Logger.info("Create SoundPool with $attrs") | |||
ref.handleGlobalLog("Create SoundPool with $attrs") |
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.
should this call the player-specific log?
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.
Creating a SoundPool is a global action in my opinion, as it can be used by multiple players. Although it is initiated by one of these. (And it would be a bit quirky to bring in the player scope in this area, as the specific player is not available here)
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.
gotcha, agreed. forgot the soundpool was shared
packages/audioplayers_platform_interface/lib/src/api/global_event.dart
Outdated
Show resolved
Hide resolved
} | ||
|
||
// See: https://github.com/flutter/packages/blob/12609a2abbb0a30b9d32af7b73599bfc834e609e/packages/video_player/video_player_android/test/android_video_player_test.dart#L270 | ||
void createNativeEventStream({ |
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.
for a followup: between this, MapParser/MethodCall extensions, OverridePrint, and more, there seems to be a lot of generic testing utils that could be extracted to their own package.
I think I could use them on gamepads for example.
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.
Ah nice, didn't noticed you started this lib 🎉 Sure, if it's more practical. Feel free to move any generic testing stuff :)
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.
Excellent refactor @Gustl22 🚀 👏 ❤️
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.
Great job! Would be good to add a paragraph to the migration doc so that the user knows what changes they have to do to migrate from the previous version.
I would also do this in a separate MR, as it concerns the version migration and not this specific MR, where the relevant steps are in the description. The migration also includes other MR like #1443 I also wonder how you handle migration in flame. Maybe the Changelog is sufficient. At least we have to make more sections in the migration guide for the different versions. But maybe that's overengineered. Or we have to ditch stuff from the migration from v0 to v1. Whats are your proposals @spydon @luanpotter ? Thank you :D |
In Flame we have the migration instructions in the bottom of the version in the changelog, so we could do the same here, and maybe mention that in the existing migration doc? |
# Description - Upgrade min Dart to v2.7.0 - Upgrade min Flutter to v3.0.0 - Adapt some code to new Dart features ## Related Issues #1352
# Description As some of the classes introduced in #1352 are quite generic and could conflict with other packages, we should rename them to be more specific to the package: - Refactor `GlobalEvent` to `GlobalAudioEvent` - Refactor `PlayerEvent` to `AudioEvent` - Refactor `Logger` to `AudioLogger` - Refactor `LogLevel` to `AudioLogLevel` PlayerEvent was renamed to have the same scheme as `GlobalAudioEvent` and so that it is more applicable to Audio and not to all players in general (e.g. media or video player). ## Breaking Change This is a breaking change regarding the current master channel, but not the published versions. **audioplayers** | Before | After | |---|---| | `GlobalEvent` | `GlobalAudioEvent` | | `PlayerEvent` | `AudioEvent` | | `Logger` | `AudioLogger` | | `LogLevel` | `AudioLogLevel` | **audioplayers_platform_interface** | Before | After | |---|---| | `GlobalEvent` | `GlobalAudioEvent` | | `PlayerEvent` | `AudioEvent` | ## Related Issues #1352
Description
PlayerEvent
) and global (GlobalEvent
) eventscreate
,dispose
andgetEventStream
toAudioplayersPlatformInterface
getGlobalEventStream
toGlobalAudioplayersPlatformInterface
player.onLog()
andAudioPlayer.global.onLog()
player.eventStream.listen().onError()
andAudioPlayer.global.eventStream.listen().onError()
Checklist
fix:
,feat:
,docs:
,chore:
etc).///
, where necessary.Breaking Change
Migration instructions
audioplayers:
AudioPlayer.global.changeLogLevel(LogLevel.info)
Logger.logLevel = LogLevel.info
AudioPlayer.global.logLevel
Logger.logLevel
AudioPlayer.global.log()
Logger.log()
orLogger.error()
AudioPlayer.global.info()
Logger.log()
AudioPlayer.global.error()
Logger.error()
ForPlayer<>
audioplayers_platform_interface:
LogLevel
audioplayers
packageStreamsInterface
ForPlayer<>
Related Issues
Closes #106
Closes #151
Closes #1266
Can handle error of #1260
Related to #208 and #933, but cannot hide Android MediaPlayer logs
This would bypass: flutter/flutter#69103