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

new-fork to merge branch #2

Merged
merged 5 commits into from
Mar 4, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.2

* Bug fixes.

## 0.6.1

* Option to stop service on closing task (Android).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ public void onLoadChildren(final String parentMediaId, final Result<List<MediaBr

@Override
public int onStartCommand(final Intent intent, int flags, int startId) {
if (intent == null) { stopSelf(); }
MediaButtonReceiver.handleIntent(mediaSession, intent);
return super.onStartCommand(intent, flags, startId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ public void onAddQueueItem(MediaMetadataCompat metadata) {
}
@Override
public void onAddQueueItemAt(MediaMetadataCompat metadata, int index) {
invokeMethod("onAddQueueItem", mediaMetadata2raw(metadata), index);
invokeMethod("onAddQueueItemAt", mediaMetadata2raw(metadata), index);
}
@Override
public void onRemoveQueueItem(MediaMetadataCompat metadata) {
Expand Down
23 changes: 17 additions & 6 deletions lib/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class PlaybackState {
/// The current playback position in milliseconds
int get currentPosition {
if (basicState == BasicPlaybackState.playing) {
return position + DateTime.now().millisecondsSinceEpoch - updateTime;
return (position +
((DateTime.now().millisecondsSinceEpoch - updateTime) *
(speed ?? 1.0)))
.toInt();
} else {
return position;
}
Expand Down Expand Up @@ -372,6 +375,9 @@ class AudioService {

static final _browseMediaChildrenSubject = BehaviorSubject<List<MediaItem>>();

/// An instance of flutter isolate
static FlutterIsolate _flutterIsolate;

/// A stream that broadcasts the children of the current browse
/// media parent.
static Stream<List<MediaItem>> get browseMediaChildrenStream =>
Expand Down Expand Up @@ -439,11 +445,15 @@ class AudioService {
_playbackStateSubject.add(_playbackState);
break;
case 'onMediaChanged':
_currentMediaItem = call.arguments[0] != null ? _raw2mediaItem(call.arguments[0]) : null;
_currentMediaItem = call.arguments[0] != null
? _raw2mediaItem(call.arguments[0])
: null;
_currentMediaItemSubject.add(_currentMediaItem);
break;
case 'onQueueChanged':
final List<Map> args = call.arguments[0] != null ? List<Map>.from(call.arguments[0]) : null;
final List<Map> args = call.arguments[0] != null
? List<Map>.from(call.arguments[0])
: null;
_queue = args?.map(_raw2mediaItem)?.toList();
_queueSubject.add(_queue);
break;
Expand Down Expand Up @@ -531,7 +541,7 @@ class AudioService {
// TODO: remove dependency on flutter_isolate by either using the
// FlutterNativeView API directly or by waiting until Flutter allows
// regular isolates to use method channels.
await FlutterIsolate.spawn(_iosIsolateEntrypoint, callbackHandle);
AudioService._flutterIsolate = await FlutterIsolate.spawn(_iosIsolateEntrypoint, callbackHandle);
}
return await _channel.invokeMethod('start', {
'callbackHandle': callbackHandle,
Expand Down Expand Up @@ -816,7 +826,7 @@ class AudioServiceBackground {
await task.onStart();
await _backgroundChannel.invokeMethod('stopped');
if (Platform.isIOS) {
FlutterIsolate.current.kill();
AudioService._flutterIsolate?.kill();
}
_backgroundChannel.setMethodCallHandler(null);
_state = _noneState;
Expand Down Expand Up @@ -865,7 +875,8 @@ class AudioServiceBackground {
'action': control.action.index,
})
.toList();
final rawSystemActions = systemActions.map((action) => action.index).toList();
final rawSystemActions =
systemActions.map((action) => action.index).toList();
await _backgroundChannel.invokeMethod('setState', [
rawControls,
rawSystemActions,
Expand Down
2 changes: 1 addition & 1 deletion 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.6.1
version: 0.6.2
homepage: https://github.com/ryanheise/audio_service

environment:
Expand Down