mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Let exoplayer handle audio becoming noisy
This commit is contained in:
parent
b320321c86
commit
dda7953ffe
2 changed files with 4 additions and 23 deletions
|
|
@ -109,6 +109,7 @@ public class MultiPlayer implements Playback {
|
||||||
exoPlayer = new SimpleExoPlayer.Builder(context)
|
exoPlayer = new SimpleExoPlayer.Builder(context)
|
||||||
.setMediaSourceFactory(new DefaultMediaSourceFactory(cacheDataSourceFactory))
|
.setMediaSourceFactory(new DefaultMediaSourceFactory(cacheDataSourceFactory))
|
||||||
.setAudioAttributes(audioAttributes, true)
|
.setAudioAttributes(audioAttributes, true)
|
||||||
|
.setHandleAudioBecomingNoisy(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
exoPlayer.addListener(eventListener);
|
exoPlayer.addListener(eventListener);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
package com.cappielloantonio.play.service;
|
package com.cappielloantonio.play.service;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
|
||||||
|
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
|
@ -15,8 +18,6 @@ import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PowerManager;
|
|
||||||
import android.os.Process;
|
|
||||||
import android.support.v4.media.MediaMetadataCompat;
|
import android.support.v4.media.MediaMetadataCompat;
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
import android.support.v4.media.session.MediaSessionCompat;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
|
|
@ -41,14 +42,6 @@ import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_AUTO;
|
|
||||||
import static com.google.android.exoplayer2.Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED;
|
|
||||||
import static com.google.android.exoplayer2.Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM;
|
|
||||||
|
|
||||||
public class MusicService extends Service implements Playback.PlaybackCallbacks {
|
public class MusicService extends Service implements Playback.PlaybackCallbacks {
|
||||||
private static final String TAG = "MusicService";
|
private static final String TAG = "MusicService";
|
||||||
|
|
@ -68,7 +61,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
public static final String META_CHANGED = PACKAGE_NAME + ".meta.changed";
|
public static final String META_CHANGED = PACKAGE_NAME + ".meta.changed";
|
||||||
public static final String QUEUE_CHANGED = PACKAGE_NAME + ".queue.changed";
|
public static final String QUEUE_CHANGED = PACKAGE_NAME + ".queue.changed";
|
||||||
|
|
||||||
public static final int TRACK_STARTED = 9;
|
|
||||||
public static final int TRACK_CHANGED = 1;
|
public static final int TRACK_CHANGED = 1;
|
||||||
public static final int TRACK_ENDED = 2;
|
public static final int TRACK_ENDED = 2;
|
||||||
public static final int PLAY_SONG = 3;
|
public static final int PLAY_SONG = 3;
|
||||||
|
|
@ -93,14 +85,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
private boolean notHandledMetaChangedForCurrentTrack;
|
private boolean notHandledMetaChangedForCurrentTrack;
|
||||||
|
|
||||||
private PlayingNotification playingNotification;
|
private PlayingNotification playingNotification;
|
||||||
private final BroadcastReceiver becomingNoisyReceiver = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, @NonNull Intent intent) {
|
|
||||||
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
|
|
||||||
pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private MediaSessionCompat mediaSession;
|
private MediaSessionCompat mediaSession;
|
||||||
private PlaybackHandler playerHandler;
|
private PlaybackHandler playerHandler;
|
||||||
private Handler uiThreadHandler;
|
private Handler uiThreadHandler;
|
||||||
|
|
@ -121,8 +105,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
|
throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
|
||||||
uiThreadHandler = new Handler();
|
uiThreadHandler = new Handler();
|
||||||
|
|
||||||
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
|
||||||
|
|
||||||
initNotification();
|
initNotification();
|
||||||
initMediaSession();
|
initMediaSession();
|
||||||
restoreState();
|
restoreState();
|
||||||
|
|
@ -234,8 +216,6 @@ public class MusicService extends Service implements Playback.PlaybackCallbacks
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
unregisterReceiver(becomingNoisyReceiver);
|
|
||||||
|
|
||||||
mediaSession.setActive(false);
|
mediaSession.setActive(false);
|
||||||
quit();
|
quit();
|
||||||
releaseResources();
|
releaseResources();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue