Skip to content

Commit

Permalink
just_audio 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jul 18, 2021
1 parent aa34276 commit 6b13610
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
5 changes: 5 additions & 0 deletions just_audio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.1

* Fix update position bug on Android.
* Compile-time option to include/exclude microphone API.

## 0.8.0

* Add buffer options via AudioLoadConfiguration for iOS/Android.
Expand Down
23 changes: 21 additions & 2 deletions just_audio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,30 @@ If you need access to the player's AudioSession ID, you can listen to `AudioPlay

### iOS

Regardless of whether your app uses the microphone, Apple will require you to add the following key to your `Info.plist` file. The message will simply be ignored if your app doesn't use the microphone:
Using the default configuration, the App Store will detect that your app uses the AVAudioSession API which includes a microphone API, and for privacy reasons it will ask you to describe your app's usage of the microphone. If your app does indeed use the microphone, you can describe your usage by editing the `Info.plist` file as follows:

```xml
<key>NSMicrophoneUsageDescription</key>
<string>... explain why you use (or don't use) the microphone ...</string>
<string>... explain why the app uses the microphone here ...</string>
```

But if your app does not use the microphone, you can pass a build option to "compile out" any microphone code so that the App Store won't ask for the above usage description. To do so, edit your `ios/Podfile` as follows:

```ruby
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)

# ADD THE NEXT SECTION
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'AUDIO_SESSION_MICROPHONE=0'
]
end

end
end
```

If you wish to connect to non-HTTPS URLS, add the following to your `Info.plist` file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void run() {

long newBufferedPosition = player.getBufferedPosition();
if (newBufferedPosition != bufferedPosition) {
bufferedPosition = newBufferedPosition;
// This method updates bufferedPosition.
broadcastPlaybackEvent();
}
switch (processingState) {
Expand Down Expand Up @@ -236,10 +236,11 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
}
}

private void updatePositionIfChanged() {
if (getCurrentPosition() == updatePosition) return;
private boolean updatePositionIfChanged() {
if (getCurrentPosition() == updatePosition) return false;
updatePosition = getCurrentPosition();
updateTime = System.currentTimeMillis();
return true;
}

private void updatePosition() {
Expand All @@ -253,9 +254,10 @@ public void onPositionDiscontinuity(int reason) {
switch (reason) {
case Player.DISCONTINUITY_REASON_PERIOD_TRANSITION:
case Player.DISCONTINUITY_REASON_SEEK:
onItemMayHaveChanged();
updateCurrentIndex();
break;
}
broadcastPlaybackEvent();
}

@Override
Expand All @@ -266,17 +268,20 @@ public void onTimelineChanged(Timeline timeline, int reason) {
initialIndex = null;
initialPos = C.TIME_UNSET;
}
onItemMayHaveChanged();
if (updateCurrentIndex()) {
broadcastPlaybackEvent();
}
}

private void onItemMayHaveChanged() {
private boolean updateCurrentIndex() {
Integer newIndex = player.getCurrentWindowIndex();
// newIndex is never null.
// currentIndex is sometimes null.
if (!newIndex.equals(currentIndex)) {
currentIndex = newIndex;
broadcastPlaybackEvent();
return true;
}
return false;
}

@Override
Expand Down Expand Up @@ -744,6 +749,7 @@ private void equalizerBandSetGain(int bandIndex, double gain) {
private void broadcastPlaybackEvent() {
final Map<String, Object> event = new HashMap<String, Object>();
Long duration = getDuration() == C.TIME_UNSET ? null : (1000 * getDuration());
bufferedPosition = player.getBufferedPosition();
event.put("processingState", processingState.ordinal());
event.put("updatePosition", 1000 * updatePosition);
event.put("updateTime", updateTime);
Expand Down
30 changes: 29 additions & 1 deletion just_audio/lib/just_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,9 @@ class AudioPlayer {
androidAudioSessionId: message.androidAudioSessionId,
);
_durationFuture = Future.value(playbackEvent.duration);
if (playbackEvent == _playbackEvent) {
return;
}
if (playbackEvent.duration != _playbackEvent.duration) {
_durationSubject.add(playbackEvent.duration);
}
Expand Down Expand Up @@ -1361,9 +1364,34 @@ class PlaybackEvent {
androidAudioSessionId ?? this.androidAudioSessionId,
);

@override
int get hashCode => hashValues(
processingState,
updateTime,
updatePosition,
bufferedPosition,
duration,
icyMetadata,
currentIndex,
androidAudioSessionId,
);

@override
bool operator ==(Object other) =>
other.runtimeType == runtimeType &&
other is PlaybackEvent &&
processingState == other.processingState &&
updateTime == other.updateTime &&
updatePosition == other.updatePosition &&
bufferedPosition == other.bufferedPosition &&
duration == other.duration &&
icyMetadata == other.icyMetadata &&
currentIndex == other.currentIndex &&
androidAudioSessionId == other.androidAudioSessionId;

@override
String toString() =>
"{processingState=$processingState, updateTime=$updateTime, updatePosition=$updatePosition}";
"{processingState=$processingState, updateTime=$updateTime, updatePosition=$updatePosition, bufferedPosition=$bufferedPosition, duration=$duration, currentIndex=$currentIndex}";
}

/// Enumerates the different processing states of a player.
Expand Down
2 changes: 1 addition & 1 deletion just_audio/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: just_audio
description: A feature-rich audio player for Flutter. Loop, clip and concatenate any sound from any source (asset/file/URL/stream) in a variety of audio formats with gapless playback.
version: 0.8.0
version: 0.8.1
homepage: https://github.com/ryanheise/just_audio/tree/master/just_audio

environment:
Expand Down

0 comments on commit 6b13610

Please sign in to comment.