fix an issue manually seeking during playback
This commit is contained in:
parent
eb5b4787ed
commit
8327c7d1ba
6 changed files with 44 additions and 16 deletions
|
|
@ -14,6 +14,7 @@ import com.dkanada.gramophone.App;
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||||
import com.dkanada.gramophone.model.Server;
|
import com.dkanada.gramophone.model.Server;
|
||||||
|
import com.dkanada.gramophone.util.NavigationUtil;
|
||||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||||
|
|
||||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||||
|
|
@ -54,6 +55,7 @@ public class SplashActivity extends AbsBaseActivity {
|
||||||
private boolean detectBatteryOptimization() {
|
private boolean detectBatteryOptimization() {
|
||||||
String packageName = getPackageName();
|
String packageName = getPackageName();
|
||||||
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
|
||||||
return !pm.isIgnoringBatteryOptimizations(packageName);
|
return !pm.isIgnoringBatteryOptimizations(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +79,7 @@ public class SplashActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
public void login() {
|
public void login() {
|
||||||
if (PreferenceUtil.getInstance(this).getServer().isEmpty()) {
|
if (PreferenceUtil.getInstance(this).getServer().isEmpty()) {
|
||||||
launchLoginActivity();
|
NavigationUtil.goToLogin(this);
|
||||||
} else {
|
} else {
|
||||||
final Context context = this;
|
final Context context = this;
|
||||||
Server server = App.getDatabase().serverDao().getServer(PreferenceUtil.getInstance(this).getServer());
|
Server server = App.getDatabase().serverDao().getServer(PreferenceUtil.getInstance(this).getServer());
|
||||||
|
|
@ -94,22 +96,14 @@ public class SplashActivity extends AbsBaseActivity {
|
||||||
App.getApiClient().ensureWebSocket();
|
App.getApiClient().ensureWebSocket();
|
||||||
App.getApiClient().ReportCapabilities(clientCapabilities, new EmptyResponse());
|
App.getApiClient().ReportCapabilities(clientCapabilities, new EmptyResponse());
|
||||||
|
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
NavigationUtil.goToMain(context);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
||||||
context.startActivity(intent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception exception) {
|
public void onError(Exception exception) {
|
||||||
launchLoginActivity();
|
NavigationUtil.goToLogin(context);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchLoginActivity() {
|
|
||||||
Intent intent = new Intent(this, LoginActivity.class);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import androidx.room.Query;
|
||||||
|
|
||||||
import com.dkanada.gramophone.model.Server;
|
import com.dkanada.gramophone.model.Server;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface ServerDao {
|
public interface ServerDao {
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
|
@ -16,6 +18,9 @@ public interface ServerDao {
|
||||||
@Delete
|
@Delete
|
||||||
void deleteServer(Server server);
|
void deleteServer(Server server);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM servers")
|
||||||
|
List<Server> getServers();
|
||||||
|
|
||||||
@Query("SELECT * FROM servers WHERE id = :id")
|
@Query("SELECT * FROM servers WHERE id = :id")
|
||||||
Server getServer(String id);
|
Server getServer(String id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
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_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;
|
import static com.google.android.exoplayer2.Player.PLAY_WHEN_READY_CHANGE_REASON_END_OF_MEDIA_ITEM;
|
||||||
|
|
||||||
public class MusicService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener, Playback.PlaybackCallbacks {
|
public class MusicService extends Service implements SharedPreferences.OnSharedPreferenceChangeListener, Playback.PlaybackCallbacks {
|
||||||
|
|
@ -1062,6 +1063,9 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
||||||
if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) {
|
if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) {
|
||||||
playerHandler.sendEmptyMessage(TRACK_CHANGED);
|
playerHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
progressHandler.sendEmptyMessage(TRACK_CHANGED);
|
progressHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
|
} else if (reason == MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED) {
|
||||||
|
progressHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||||
|
prepareNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,6 @@ public class LocalPlayer implements Playback {
|
||||||
private PlaybackCallbacks callbacks;
|
private PlaybackCallbacks callbacks;
|
||||||
|
|
||||||
private final ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
private final ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
||||||
@Override
|
|
||||||
public void onIsLoadingChanged(boolean isLoading) {
|
|
||||||
Log.i(TAG, String.format("onIsLoadingChanged: %b", isLoading));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
|
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
|
||||||
Log.i(TAG, String.format("onPlayWhenReadyChanged: %b %d", playWhenReady, reason));
|
Log.i(TAG, String.format("onPlayWhenReadyChanged: %b %d", playWhenReady, reason));
|
||||||
|
|
@ -60,6 +55,9 @@ public class LocalPlayer implements Playback {
|
||||||
|
|
||||||
if (exoPlayer.getMediaItemCount() > 1) {
|
if (exoPlayer.getMediaItemCount() > 1) {
|
||||||
exoPlayer.removeMediaItem(0);
|
exoPlayer.removeMediaItem(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callbacks != null) {
|
||||||
callbacks.onTrackChanged(reason);
|
callbacks.onTrackChanged(reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.dkanada.gramophone.util;
|
package com.dkanada.gramophone.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
@ -8,6 +9,8 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityOptionsCompat;
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
import androidx.core.util.Pair;
|
import androidx.core.util.Pair;
|
||||||
|
|
||||||
|
import com.dkanada.gramophone.activities.LoginActivity;
|
||||||
|
import com.dkanada.gramophone.activities.MainActivity;
|
||||||
import com.dkanada.gramophone.model.Album;
|
import com.dkanada.gramophone.model.Album;
|
||||||
import com.dkanada.gramophone.model.Artist;
|
import com.dkanada.gramophone.model.Artist;
|
||||||
import com.dkanada.gramophone.model.Genre;
|
import com.dkanada.gramophone.model.Genre;
|
||||||
|
|
@ -18,6 +21,19 @@ import com.dkanada.gramophone.activities.details.GenreDetailActivity;
|
||||||
import com.dkanada.gramophone.activities.details.PlaylistDetailActivity;
|
import com.dkanada.gramophone.activities.details.PlaylistDetailActivity;
|
||||||
|
|
||||||
public class NavigationUtil {
|
public class NavigationUtil {
|
||||||
|
public static void goToLogin(@NonNull final Context context) {
|
||||||
|
final Intent intent = new Intent(context, LoginActivity.class);
|
||||||
|
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void goToMain(@NonNull final Context context) {
|
||||||
|
final Intent intent = new Intent(context, MainActivity.class);
|
||||||
|
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
public static void goToArtist(@NonNull final Activity activity, final Artist artist, @Nullable Pair... sharedElements) {
|
public static void goToArtist(@NonNull final Activity activity, final Artist artist, @Nullable Pair... sharedElements) {
|
||||||
final Intent intent = new Intent(activity, ArtistDetailActivity.class);
|
final Intent intent = new Intent(activity, ArtistDetailActivity.class);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public final class PreferenceUtil {
|
public final class PreferenceUtil {
|
||||||
public static final String SERVER = "server";
|
public static final String SERVER = "server";
|
||||||
|
public static final String USER = "user";
|
||||||
|
|
||||||
public static final String SHUFFLE = "shuffle";
|
public static final String SHUFFLE = "shuffle";
|
||||||
public static final String REPEAT = "repeat";
|
public static final String REPEAT = "repeat";
|
||||||
|
|
@ -474,4 +475,14 @@ public final class PreferenceUtil {
|
||||||
editor.putString(SERVER, server);
|
editor.putString(SERVER, server);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return mPreferences.getString(USER, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||||
|
editor.putString(USER, user);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue