Android Open Source - simpleplayer Player State






From Project

Back to project page simpleplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project simpleplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sergez.splayer.util;
//  www  .  ja  v  a2s.c  om
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.sergez.splayer.enums.RepeatState;
import org.sergez.splayer.enums.ShuffleState;
import org.sergez.splayer.service.SimplePlayerService;

/**
 * @author Sergii Zhuk
 *         Date: 13.10.13
 *         Time: 12:21
 */
public class PlayerState {
  public static final String PREF_CURRENT_FILE = "playerServiceFile";
  public static final String PREF_CURRENT_FILE_PROGRESS = "playerServiceProgress";
  public static final String PREF_SHUFFLE = "playerShuffleState";
  public static final String PREF_REPEAT = "playerRepeatState";

  public int playerServiceProgress;
  public String playerServiceFile;
  public RepeatState repeatState;
  public ShuffleState shuffleState;

  public static PlayerState loadState(Context context) {
    PlayerState state = new PlayerState();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    state.playerServiceProgress = prefs.getInt(PREF_CURRENT_FILE_PROGRESS, 0);
    state.playerServiceFile = prefs.getString(PREF_CURRENT_FILE, "");
    state.repeatState = RepeatState.values()[prefs.getInt(PREF_REPEAT, RepeatState.NO_REPEAT.ordinal())];
    state.shuffleState = ShuffleState.values()[prefs.getInt(PREF_SHUFFLE, ShuffleState.SHUFFLE_OFF.ordinal())];
    return state;

  }

  public static void saveState(Context context, PlayerState playerState) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString(PREF_CURRENT_FILE, playerState.playerServiceFile);
    editor.putInt(PREF_CURRENT_FILE_PROGRESS, playerState.playerServiceProgress);
    editor.putInt(PREF_SHUFFLE, playerState.shuffleState.ordinal());
    editor.putInt(PREF_REPEAT, playerState.repeatState.ordinal());
    editor.commit();
  }

  public static void saveState(SimplePlayerService playerServiceWithState) {
    PlayerState playerState = new PlayerState();
    playerState.repeatState = playerServiceWithState.repeatState;
    playerState.shuffleState = playerServiceWithState.shuffleState;
    playerState.playerServiceFile = playerServiceWithState.getCurrentlyPlayingFilePath();
    playerState.playerServiceProgress = playerServiceWithState.getCurrentPosition();
    saveState(playerServiceWithState, playerState);
  }

  private PlayerState() {

  }
}




Java Source Code List

org.sergez.splayer.activity.AnimationMakeGoneListener.java
org.sergez.splayer.activity.AudioFxDemo.java
org.sergez.splayer.activity.DonationActivity.java
org.sergez.splayer.activity.ListData.java
org.sergez.splayer.activity.PlayFileAdapter.java
org.sergez.splayer.activity.PreferencesActivity.java
org.sergez.splayer.activity.SimplePlayerActivity.java
org.sergez.splayer.enums.RepeatState.java
org.sergez.splayer.enums.ShuffleState.java
org.sergez.splayer.inappbilling.Base64DecoderException.java
org.sergez.splayer.inappbilling.Base64.java
org.sergez.splayer.inappbilling.IabException.java
org.sergez.splayer.inappbilling.IabHelper.java
org.sergez.splayer.inappbilling.IabResult.java
org.sergez.splayer.inappbilling.Inventory.java
org.sergez.splayer.inappbilling.Purchase.java
org.sergez.splayer.inappbilling.Security.java
org.sergez.splayer.inappbilling.SkuDetails.java
org.sergez.splayer.service.SimplePlayerService.java
org.sergez.splayer.util.Constants.java
org.sergez.splayer.util.DialogUtils.java
org.sergez.splayer.util.DurationAlbumID.java
org.sergez.splayer.util.FileFormat.java
org.sergez.splayer.util.MediaFileData.java
org.sergez.splayer.util.MediaFileUtil.java
org.sergez.splayer.util.PlayerState.java
org.sergez.splayer.util.PrefsConstants.java
org.sergez.splayer.util.PrefsController.java
org.sergez.splayer.util.SortIgnoreCase.java
org.sergez.splayer.util.UIStateController.java
org.sergez.splayer.util.Utils.java
org.sergez.splayer.view.ScrollingTextView.java