Skip to content
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

Fix error handling in onLoadChildren, onLoadItem and onSearch #1086

Open
wants to merge 3 commits into
base: minor
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions audio_service/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.18.16
* Fix error handling in onLoadChildren, onLoadItem and onSearch (@dsst95)

## 0.18.15

* Add deep link support for FlutterFragmentActivity (@jan-milovanovic).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,13 @@ public void onLoadChildren(final String parentMediaId, final MediaBrowserService
audioHandlerInterface.invokeMethod("getChildren", args, new MethodChannel.Result() {
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
result.sendError(new Bundle());
setErrorState(errorCode, errorMessage);
result.sendResult(null);
}

@Override
public void notImplemented() {
result.sendError(new Bundle());
result.sendResult(null);
}

@Override
Expand All @@ -583,12 +584,13 @@ public void onLoadItem(String itemId, final MediaBrowserServiceCompat.Result<Med
audioHandlerInterface.invokeMethod("getMediaItem", args, new MethodChannel.Result() {
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
result.sendError(new Bundle());
setErrorState(errorCode, errorMessage);
result.sendResult(null);
}

@Override
public void notImplemented() {
result.sendError(new Bundle());
result.sendResult(null);
}

@Override
Expand Down Expand Up @@ -616,12 +618,13 @@ public void onSearch(String query, Bundle extras, final MediaBrowserServiceCompa
audioHandlerInterface.invokeMethod("search", args, new MethodChannel.Result() {
@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
result.sendError(new Bundle());
setErrorState(errorCode, errorMessage);
result.sendResult(null);
}

@Override
public void notImplemented() {
result.sendError(new Bundle());
result.sendResult(null);
}

@Override
Expand Down Expand Up @@ -1019,6 +1022,25 @@ private void destroy() {
if (silenceAudioTrack != null)
silenceAudioTrack.release();
}

private void setErrorState(String errorCode, String errorMessage) {
AudioService.instance.setState(
new ArrayList<MediaControl>(),
0,
null,
AudioProcessingState.error,
false,
0,
0,
0,
0,
Integer.parseInt(errorCode),
errorMessage,
0,
0,
false,
null);
}
}

private static List<Map<?, ?>> mediaItems2raw(List<MediaBrowserCompat.MediaItem> mediaItems) {
Expand Down
2 changes: 1 addition & 1 deletion audio_service/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: audio_service
description: Flutter plugin to play audio in the background while the screen is off.
version: 0.18.15
version: 0.18.16
repository: https://github.com/ryanheise/audio_service/tree/minor/audio_service
issue_tracker: https://github.com/ryanheise/audio_service/issues
topics:
Expand Down