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.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.model.Server;
|
||||
import com.dkanada.gramophone.util.NavigationUtil;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||
|
|
@ -54,6 +55,7 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
private boolean detectBatteryOptimization() {
|
||||
String packageName = getPackageName();
|
||||
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
|
||||
return !pm.isIgnoringBatteryOptimizations(packageName);
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +79,7 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
|
||||
public void login() {
|
||||
if (PreferenceUtil.getInstance(this).getServer().isEmpty()) {
|
||||
launchLoginActivity();
|
||||
NavigationUtil.goToLogin(this);
|
||||
} else {
|
||||
final Context context = this;
|
||||
Server server = App.getDatabase().serverDao().getServer(PreferenceUtil.getInstance(this).getServer());
|
||||
|
|
@ -94,22 +96,14 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
App.getApiClient().ensureWebSocket();
|
||||
App.getApiClient().ReportCapabilities(clientCapabilities, new EmptyResponse());
|
||||
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
context.startActivity(intent);
|
||||
NavigationUtil.goToMain(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
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 java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface ServerDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
|
|
@ -16,6 +18,9 @@ public interface ServerDao {
|
|||
@Delete
|
||||
void deleteServer(Server server);
|
||||
|
||||
@Query("SELECT * FROM servers")
|
||||
List<Server> getServers();
|
||||
|
||||
@Query("SELECT * FROM servers WHERE id = :id")
|
||||
Server getServer(String id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ 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 SharedPreferences.OnSharedPreferenceChangeListener, Playback.PlaybackCallbacks {
|
||||
|
|
@ -1062,6 +1063,9 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
if (reason == MEDIA_ITEM_TRANSITION_REASON_AUTO) {
|
||||
playerHandler.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 final ExoPlayer.EventListener eventListener = new ExoPlayer.EventListener() {
|
||||
@Override
|
||||
public void onIsLoadingChanged(boolean isLoading) {
|
||||
Log.i(TAG, String.format("onIsLoadingChanged: %b", isLoading));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayWhenReadyChanged(boolean playWhenReady, int reason) {
|
||||
Log.i(TAG, String.format("onPlayWhenReadyChanged: %b %d", playWhenReady, reason));
|
||||
|
|
@ -60,6 +55,9 @@ public class LocalPlayer implements Playback {
|
|||
|
||||
if (exoPlayer.getMediaItemCount() > 1) {
|
||||
exoPlayer.removeMediaItem(0);
|
||||
}
|
||||
|
||||
if (callbacks != null) {
|
||||
callbacks.onTrackChanged(reason);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.dkanada.gramophone.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
|
@ -8,6 +9,8 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.app.ActivityOptionsCompat;
|
||||
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.Artist;
|
||||
import com.dkanada.gramophone.model.Genre;
|
||||
|
|
@ -18,6 +21,19 @@ import com.dkanada.gramophone.activities.details.GenreDetailActivity;
|
|||
import com.dkanada.gramophone.activities.details.PlaylistDetailActivity;
|
||||
|
||||
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) {
|
||||
final Intent intent = new Intent(activity, ArtistDetailActivity.class);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.Set;
|
|||
|
||||
public final class PreferenceUtil {
|
||||
public static final String SERVER = "server";
|
||||
public static final String USER = "user";
|
||||
|
||||
public static final String SHUFFLE = "shuffle";
|
||||
public static final String REPEAT = "repeat";
|
||||
|
|
@ -474,4 +475,14 @@ public final class PreferenceUtil {
|
|||
editor.putString(SERVER, server);
|
||||
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