-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: improve separation of global audioplayer interface (#1443)
# Description AudioPlayers platform communication consists of two parts: the `AudioPlayer` scope and the `Global` scope. These were not separated consistently, so one was used as implementation and the other as interface. Now both scopes are handled the same way: * `AudioPlayer`: player specific processing and interaction via `AudioplayersPlatformInterface` * `GlobalAudioScope`: global processing and interaction via `GlobalAudioplayersPlatformInterface` * `AudioplayersPlatformInterface`: interface to player platform channel (methods and events), holds an instance implementation like `AudioplayersPlatform` or `WebAudioplayersPlatform` * `GlobalAudioplayersPlatformInterface`: interface to global platform channel (methods and events), holds an instance implementation like `GlobalAudioplayersPlatform` or `WebGlobalAudioplayersPlatform` * `AudioplayersPlatform`: platform channel implementation of `AudioplayersPlatformInterface` * `GlobalAudioplayersPlatform`: platform channel implementation of `GlobalAudioplayersPlatformInterface` Also deprecated `AudioPlayer.global.setGlobalAudioContext()` in favor of `AudioPlayer.global.setAudioContext()`. ## Migration instructions **audioplayers**: | Before | After | |---|---| | `GlobalPlatformInterface` | `GlobalAudioScope` | | `AudioPlayer.global.setGlobalAudioContext()` | `AudioPlayer.global.setAudioContext()` | **audioplayers_platform_interface**: | Before | After | |---|---| | `AudioplayersPlatform` | `AudioplayersPlatformInterface` | | `MethodChannelAudioplayersPlatform` | `AudioplayersPlatform` | | `GlobalPlatformInterface` | `GlobalAudioplayersPlatformInterface` | | `MethodChannelGlobalPlatform` | `GlobalAudioplayersPlatform` | **audioplayers_web**: | Before | After | |---|---| | `AudioplayersPlugin` | `AudioplayersPlugin`, `WebAudioplayersPlatform` and `WebGlobalAudioplayersPlatform` |
- Loading branch information
Showing
14 changed files
with
108 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:audioplayers_platform_interface/audioplayers_platform_interface.dart'; | ||
|
||
/// Handle global audio scope like calls and events concerning all AudioPlayers. | ||
class GlobalAudioScope { | ||
static final _platform = GlobalAudioplayersPlatformInterface.instance; | ||
|
||
LogLevel get logLevel => _platform.logLevel; | ||
|
||
Future<void> changeLogLevel(LogLevel level) => | ||
_platform.changeLogLevel(level); | ||
|
||
void log(LogLevel level, String message) => _platform.log(level, message); | ||
|
||
void info(String message) => _platform.info(message); | ||
|
||
void error(String message) => _platform.error(message); | ||
|
||
Future<void> setAudioContext(AudioContext ctx) => | ||
_platform.setGlobalAudioContext(ctx); | ||
|
||
@Deprecated('Use `setAudioContext()` instead.') | ||
Future<void> setGlobalAudioContext(AudioContext ctx) => | ||
_platform.setGlobalAudioContext(ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 2 additions & 22 deletions
24
...ce/lib/src/global_platform_interface.dart → ...lib/src/global_audioplayers_platform.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/audioplayers_platform_interface/lib/src/global_audioplayers_platform_interface.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:audioplayers_platform_interface/src/api/audio_context.dart'; | ||
import 'package:audioplayers_platform_interface/src/api/log_level.dart'; | ||
import 'package:audioplayers_platform_interface/src/global_audioplayers_platform.dart'; | ||
|
||
abstract class GlobalAudioplayersPlatformInterface { | ||
static GlobalAudioplayersPlatformInterface instance = | ||
GlobalAudioplayersPlatform(); | ||
|
||
LogLevel get logLevel; | ||
|
||
Future<void> changeLogLevel(LogLevel value); | ||
|
||
Future<void> setGlobalAudioContext(AudioContext ctx); | ||
|
||
void log(LogLevel level, String message) { | ||
if (level.getLevel() <= logLevel.getLevel()) { | ||
// ignore: avoid_print | ||
print(message); | ||
} | ||
} | ||
|
||
void info(String message) => log(LogLevel.info, message); | ||
|
||
void error(String message) => log(LogLevel.error, message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/audioplayers_web/lib/global_audioplayers_web.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:audioplayers_platform_interface/audioplayers_platform_interface.dart'; | ||
|
||
class WebGlobalAudioplayersPlatform | ||
extends GlobalAudioplayersPlatformInterface { | ||
// Web implementation currently does not log anything | ||
LogLevel _level = LogLevel.error; | ||
|
||
@override | ||
Future<void> changeLogLevel(LogLevel value) async { | ||
_level = value; | ||
} | ||
|
||
@override | ||
LogLevel get logLevel => _level; | ||
|
||
@override | ||
Future<void> setGlobalAudioContext(AudioContext ctx) async { | ||
// no-op: web does not support changing audio context | ||
} | ||
} |