Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
luanpotter committed Oct 12, 2020
1 parent 574c773 commit 8fa8f6f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ For a Local File, add the `isLocal` parameter:
```

To play a file in the form of a data buffer (Uint8List), use the method `playBytes`.
This currently is not supported when calling from `audio_cache` and only works for Android (requiring API >= 23).
This currently only works for Android (requiring API >= 23).

```dart
playLocal() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ void play(Context context) {
this.player = createPlayer(context);
if (dataSource != null) {
setMediaSource(dataSource);
}
else {
} else {
this.setSource(url);
}
this.player.prepareAsync();
Expand Down
16 changes: 9 additions & 7 deletions lib/audio_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ class AudioCache {
/// Plays the given [fileName] by a byte source.
///
/// This is no different than calling this API via AudioPlayer, except it will return (if applicable) the cached AudioPlayer.
Future<AudioPlayer> playBytes(Uint8List fileBytes,
{double volume = 1.0,
bool isNotification,
PlayerMode mode = PlayerMode.MEDIA_PLAYER,
bool loop = false,
bool stayAwake,
bool recordingActive}) async {
Future<AudioPlayer> playBytes(
Uint8List fileBytes, {
double volume = 1.0,
bool isNotification,
PlayerMode mode = PlayerMode.MEDIA_PLAYER,
bool loop = false,
bool stayAwake,
bool recordingActive,
}) async {
AudioPlayer player = _player(mode);

if (loop) {
Expand Down
55 changes: 32 additions & 23 deletions lib/audioplayers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class AudioPlayer {
/// `callback` is invoked on a background isolate and will not have direct
/// access to the state held by the main isolate (or any other isolate).
Future<bool> monitorNotificationStateChanges(
void Function(AudioPlayerState value) callback) async {
void Function(AudioPlayerState value) callback,
) async {
if (callback == null) {
throw ArgumentError.notNull('callback');
}
Expand Down Expand Up @@ -412,13 +413,15 @@ class AudioPlayer {
/// Plays audio in the form of a byte array.
///
/// respectSilence and stayAwake are not implemented on macOS.
Future<int> playBytes(Uint8List bytes,
{double volume = 1.0,
// position must be null by default to be compatible with radio streams
Duration position,
bool respectSilence = false,
bool stayAwake = false,
bool recordingActive = false}) async {
Future<int> playBytes(
Uint8List bytes, {
double volume = 1.0,
// position must be null by default to be compatible with radio streams
Duration position,
bool respectSilence = false,
bool stayAwake = false,
bool recordingActive = false,
}) async {
volume ??= 1.0;
respectSilence ??= false;
stayAwake ??= false;
Expand Down Expand Up @@ -535,17 +538,18 @@ class AudioPlayer {
/// Sets the notification bar for lock screen and notification area in iOS for now.
///
/// Specify atleast title
Future<dynamic> setNotification(
{String title,
String albumTitle,
String artist,
String imageUrl,
Duration forwardSkipInterval = Duration.zero,
Duration backwardSkipInterval = Duration.zero,
Duration duration = Duration.zero,
Duration elapsedTime = Duration.zero,
bool hasPreviousTrack = false,
bool hasNextTrack = false}) {
Future<dynamic> setNotification({
String title,
String albumTitle,
String artist,
String imageUrl,
Duration forwardSkipInterval = Duration.zero,
Duration backwardSkipInterval = Duration.zero,
Duration duration = Duration.zero,
Duration elapsedTime = Duration.zero,
bool hasPreviousTrack = false,
bool hasNextTrack = false,
}) {
return _invokeMethod('setNotification', {
'title': title ?? '',
'albumTitle': albumTitle ?? '',
Expand All @@ -568,11 +572,16 @@ class AudioPlayer {
/// this method.
///
/// respectSilence is not implemented on macOS.
Future<int> setUrl(String url,
{bool isLocal: false, bool respectSilence = false}) {
Future<int> setUrl(
String url, {
bool isLocal: false,
bool respectSilence = false,
}) {
isLocal = isLocalUrl(url);
return _invokeMethod('setUrl',
{'url': url, 'isLocal': isLocal, 'respectSilence': respectSilence});
return _invokeMethod(
'setUrl',
{'url': url, 'isLocal': isLocal, 'respectSilence': respectSilence},
);
}

/// Get audio duration after setting url.
Expand Down

0 comments on commit 8fa8f6f

Please sign in to comment.