Skip to content

Commit b412fe6

Browse files
committed
Broadcast audio session id to allow application of external audio effects
#163
1 parent 3733883 commit b412fe6

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.brouken.player"
1111
minSdkVersion 21
1212
targetSdkVersion 30
13-
versionCode 52
14-
versionName "0.52"
13+
versionCode 53
14+
versionName "0.53"
1515
archivesBaseName = "Just.Player.v${versionName}"
1616
}
1717

app/src/main/java/com/brouken/player/PlayerActivity.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.graphics.Typeface;
2525
import android.graphics.drawable.Icon;
2626
import android.media.AudioManager;
27+
import android.media.audiofx.AudioEffect;
2728
import android.media.audiofx.LoudnessEnhancer;
2829
import android.net.Uri;
2930
import android.os.Build;
@@ -926,13 +927,13 @@ public void onAnimationEnd(Animator animation) {
926927
loudnessEnhancer.release();
927928
}
928929
try {
929-
int audioSessionId = C.generateAudioSessionIdV21(this);
930-
loudnessEnhancer = new LoudnessEnhancer(audioSessionId);
931-
player.setAudioSessionId(audioSessionId);
930+
loudnessEnhancer = new LoudnessEnhancer(player.getAudioSessionId());
932931
} catch (RuntimeException e) {
933932
e.printStackTrace();
934933
}
935934

935+
notifyAudioSessionUpdate(true);
936+
936937
videoLoading = true;
937938

938939
updateLoading(true);
@@ -974,6 +975,8 @@ public void onAnimationEnd(Animator animation) {
974975

975976
public void releasePlayer() {
976977
if (player != null) {
978+
notifyAudioSessionUpdate(false);
979+
977980
mediaSession.setActive(false);
978981
mediaSession.release();
979982

@@ -1013,6 +1016,7 @@ public void onAudioSessionIdChanged(int audioSessionId) {
10131016
} catch (RuntimeException e) {
10141017
e.printStackTrace();
10151018
}
1019+
notifyAudioSessionUpdate(true);
10161020
}
10171021

10181022
@Override
@@ -1742,4 +1746,15 @@ void skipToNext() {
17421746
initializePlayer();
17431747
}
17441748
}
1749+
1750+
void notifyAudioSessionUpdate(final boolean active) {
1751+
final Intent intent = new Intent(active ? AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION
1752+
: AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
1753+
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, player.getAudioSessionId());
1754+
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
1755+
if (active) {
1756+
intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MOVIE);
1757+
}
1758+
sendBroadcast(intent);
1759+
}
17451760
}

0 commit comments

Comments
 (0)