Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/audioplayers/example/integration_test/lib_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,31 @@ void main() async {
skip: !features.hasRespectSilence,
);

testWidgets(
'Set global AudioContextConfig on unsupported platforms',
(WidgetTester tester) async {
final audioContext = AudioContextConfig().build();
final globalLogFuture = AudioPlayer.global.onLog.first;
await AudioPlayer.global.setAudioContext(audioContext);

expect(
await globalLogFuture,
contains('Setting AudioContext is not supported'),
);

final player = AudioPlayer();
final logFuture = player.onLog.first;
await player.setAudioContext(audioContext);
expect(
await logFuture,
contains('Setting AudioContext is not supported'),
);

await player.dispose();
},
skip: features.hasRespectSilence,
);

/// Android and iOS only: Play the same sound twice with a different audio
/// context each. This test can be executed on a device, with either
/// "Silent", "Vibrate" or "Ring" mode. In "Silent" or "Vibrate" mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,28 @@ public class SwiftAudioplayersDarwinPlugin: NSObject, FlutterPlugin {

// global handlers (no playerId)
if method == "setAudioContext" {
do {
guard let context = try AudioContext.parse(args: args) else {
#if os(macOS)
globalEvents.onLog(message: "Setting AudioContext is not supported on macOS")
#else
do {
guard let context = try AudioContext.parse(args: args) else {
result(
FlutterError(
code: "DarwinAudioError",
message: "Error calling setAudioContext, context could not be parsed",
details: nil))
return
}
globalContext = context

try globalContext.apply()
} catch {
result(
FlutterError(
code: "DarwinAudioError",
message: "Error calling setAudioContext, context could not be parsed", details: nil))
return
code: "DarwinAudioError", message: "Error configuring global audio session: \(error)",
details: nil))
}
globalContext = context

try globalContext.apply()
} catch AudioPlayerError.warning(let warnMsg) {
globalEvents.onLog(message: warnMsg)
} catch {
result(
FlutterError(
code: "DarwinAudioError", message: "Error configuring global audio session: \(error)",
details: nil))
}
#endif
} else if method == "emitLog" {
guard let message = args["message"] as? String else {
result(
Expand Down Expand Up @@ -286,29 +289,32 @@ public class SwiftAudioplayersDarwinPlugin: NSObject, FlutterPlugin {
} else if method == "setPlayerMode" {
// no-op for darwin; only one player mode
} else if method == "setAudioContext" {
player.eventHandler.onLog(
message:
"iOS does not allow for player-specific audio contexts; `setAudioContext` will set the global audio context instead (like `global.setAudioContext`)."
)
do {
guard let context = try AudioContext.parse(args: args) else {
#if os(macOS)
player.eventHandler.onLog(message: "Setting AudioContext is not supported on macOS")
#else
player.eventHandler.onLog(
message:
"iOS does not allow for player-specific audio contexts; `setAudioContext` will set the global audio context instead (like `global.setAudioContext`)."
)
do {
guard let context = try AudioContext.parse(args: args) else {
result(
FlutterError(
code: "DarwinAudioError",
message: "Error calling setAudioContext, context could not be parsed",
details: nil))
return
}
globalContext = context

try globalContext.apply()
} catch {
result(
FlutterError(
code: "DarwinAudioError",
message: "Error calling setAudioContext, context could not be parsed", details: nil))
return
code: "DarwinAudioError", message: "Error configuring audio session: \(error)",
details: nil))
}
globalContext = context

try globalContext.apply()
} catch AudioPlayerError.warning(let warnMsg) {
globalEvents.onLog(message: warnMsg)
} catch {
result(
FlutterError(
code: "DarwinAudioError", message: "Error configuring audio session: \(error)",
details: nil))
}
#endif
} else if method == "emitLog" {
guard let message = args["message"] as? String else {
result(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ static void audioplayers_linux_plugin_handle_method_call(
} else if (strcmp(method, "setPlayerMode") == 0) {
// TODO check support for low latency mode:
// https://gstreamer.freedesktop.org/documentation/additional/design/latency.html?gi-language=c
} else if (strcmp(method, "setAudioContext") == 0) {
player->OnLog("Setting AudioContext is not supported on Linux");
} else if (strcmp(method, "setBalance") == 0) {
auto flBalance = fl_value_lookup_string(args, "balance");
double balance =
Expand Down Expand Up @@ -317,4 +319,4 @@ void audioplayers_linux_plugin_register_with_registrar(
// No need to set handler for `globalEvents` as no events are received.

g_object_unref(plugin);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ void AudioplayersWindowsPlugin::HandleMethodCall(
}
} else if (method_call.method_name().compare("setPlayerMode") == 0) {
// windows doesn't have multiple player modes, so this should no-op
} else if (method_call.method_name().compare("setAudioContext") == 0) {
player->OnLog("Setting AudioContext is not supported on Windows");
} else if (method_call.method_name().compare("setBalance") == 0) {
auto balance = GetArgument<double>("balance", args, 0.0);
player->SetBalance(balance);
Expand Down