rename some existing methods in the playback interface
This commit is contained in:
parent
569f2240ff
commit
e6ad84f16c
4 changed files with 26 additions and 23 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
package com.dkanada.gramophone.helper;
|
package com.dkanada.gramophone.helper;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class StopWatch {
|
public class StopWatch {
|
||||||
|
|
@ -40,6 +42,7 @@ public class StopWatch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format(Locale.getDefault(), "%d millis", getElapsedTime());
|
return String.format(Locale.getDefault(), "%d millis", getElapsedTime());
|
||||||
|
|
|
||||||
|
|
@ -247,24 +247,24 @@ public class MultiPlayer implements Playback {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int position() {
|
public int getPosition() {
|
||||||
if (!isReady) return -1;
|
if (!isReady) return -1;
|
||||||
return (int) exoPlayer.getCurrentPosition();
|
return (int) exoPlayer.getCurrentPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int duration() {
|
public int getDuration() {
|
||||||
if (!isReady) return -1;
|
if (!isReady) return -1;
|
||||||
return (int) exoPlayer.getDuration();
|
return (int) exoPlayer.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void seek(int position) {
|
public void setPosition(int position) {
|
||||||
exoPlayer.seekTo(position);
|
exoPlayer.seekTo(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void volume(float volume) {
|
public void setVolume(int volume) {
|
||||||
exoPlayer.setVolume(volume);
|
exoPlayer.setVolume(volume / 100f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -886,11 +886,11 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSongProgressMillis() {
|
public int getSongProgressMillis() {
|
||||||
return playback.position();
|
return playback.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSongDurationMillis() {
|
public int getSongDurationMillis() {
|
||||||
return playback.duration();
|
return playback.getDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getQueueDurationMillis(int position) {
|
public long getQueueDurationMillis(int position) {
|
||||||
|
|
@ -904,7 +904,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
|
|
||||||
public int seek(int millis) {
|
public int seek(int millis) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
playback.seek(millis);
|
playback.setPosition(millis);
|
||||||
throttledSeekHandler.notifySeek();
|
throttledSeekHandler.notifySeek();
|
||||||
return millis;
|
return millis;
|
||||||
}
|
}
|
||||||
|
|
@ -1060,7 +1060,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
private static final class PlaybackHandler extends Handler {
|
private static final class PlaybackHandler extends Handler {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final WeakReference<MusicService> mService;
|
private final WeakReference<MusicService> mService;
|
||||||
private float currentDuckVolume = 1.0f;
|
private int currentDuckVolume = 100;
|
||||||
|
|
||||||
public PlaybackHandler(final MusicService service, @NonNull final Looper looper) {
|
public PlaybackHandler(final MusicService service, @NonNull final Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
|
|
@ -1077,32 +1077,32 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case DUCK:
|
case DUCK:
|
||||||
if (PreferenceUtil.getInstance(service).getAudioDucking()) {
|
if (PreferenceUtil.getInstance(service).getAudioDucking()) {
|
||||||
currentDuckVolume -= 0.05f;
|
currentDuckVolume -= 5;
|
||||||
if (currentDuckVolume > 0.2f) {
|
if (currentDuckVolume > 20) {
|
||||||
sendEmptyMessageDelayed(DUCK, 10);
|
sendEmptyMessageDelayed(DUCK, 10);
|
||||||
} else {
|
} else {
|
||||||
currentDuckVolume = 0.2f;
|
currentDuckVolume = 20;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentDuckVolume = 1f;
|
currentDuckVolume = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
service.playback.volume(currentDuckVolume);
|
service.playback.setVolume(currentDuckVolume);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UNDUCK:
|
case UNDUCK:
|
||||||
if (PreferenceUtil.getInstance(service).getAudioDucking()) {
|
if (PreferenceUtil.getInstance(service).getAudioDucking()) {
|
||||||
currentDuckVolume += 0.03f;
|
currentDuckVolume += 3;
|
||||||
if (currentDuckVolume < 1f) {
|
if (currentDuckVolume < 100) {
|
||||||
sendEmptyMessageDelayed(UNDUCK, 10);
|
sendEmptyMessageDelayed(UNDUCK, 10);
|
||||||
} else {
|
} else {
|
||||||
currentDuckVolume = 1f;
|
currentDuckVolume = 100;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
currentDuckVolume = 1f;
|
currentDuckVolume = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
service.playback.volume(currentDuckVolume);
|
service.playback.setVolume(currentDuckVolume);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TRACK_WENT_TO_NEXT:
|
case TRACK_WENT_TO_NEXT:
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ public interface Playback {
|
||||||
|
|
||||||
boolean isPlaying();
|
boolean isPlaying();
|
||||||
|
|
||||||
int position();
|
int getPosition();
|
||||||
|
|
||||||
int duration();
|
int getDuration();
|
||||||
|
|
||||||
void seek(int position);
|
void setPosition(int position);
|
||||||
|
|
||||||
void volume(float volume);
|
void setVolume(int volume);
|
||||||
|
|
||||||
interface PlaybackCallbacks {
|
interface PlaybackCallbacks {
|
||||||
void onTrackStarted();
|
void onTrackStarted();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue