public class AppWidgetPlayerState
extends java.lang.Object
implements android.os.Parcelable
AppWidget
中访问播放器状态。
当播放器状态改变时,会发送一个 ACTION_PLAYER_STATE_CHANGED
广播,该广播的 Category 是你的
PlayerService 的完整类名(如 snow.player.demo.MyPlayerService
)。可以为你的
AppWidgetProvider
添加一个监听该广播的 <intent-filter>
,并在接收到该广播时更新你的 AppWidget。
例:
<receiver android:name=".MyAppWidgetProvider">
...
<intent-filter>
<action android:name="snow.player.appwidget.action.PLAYER_STATE_CHANGED" />
<category android:name="snow.player.demo.MyPlayerService"/>
</intent-filter>
</receiver>
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
ACTION_PLAYER_STATE_CHANGED |
static android.os.Parcelable.Creator<AppWidgetPlayerState> |
CREATOR |
限定符 | 构造器和说明 |
---|---|
protected |
AppWidgetPlayerState(android.os.Parcel in) |
|
AppWidgetPlayerState(PlaybackState playbackState,
MusicItem playingMusicItem,
PlayMode playMode,
float speed,
long playProgress,
long playProgressUpdateTime,
boolean preparing,
boolean prepared,
boolean stalled,
java.lang.String errorMessage) |
限定符和类型 | 方法和说明 |
---|---|
int |
describeContents() |
static AppWidgetPlayerState |
emptyState() |
java.lang.String |
getErrorMessage() |
PlaybackState |
getPlaybackState() |
static AppWidgetPlayerState |
getPlayerState(android.content.Context context,
java.lang.Class<? extends PlayerService> playerService) |
MusicItem |
getPlayingMusicItem() |
PlayMode |
getPlayMode() |
long |
getPlayProgress() |
long |
getPlayProgressUpdateTime() |
float |
getSpeed() |
boolean |
isPrepared() |
boolean |
isPreparing() |
static boolean |
isServiceAlive(android.content.Context context,
java.lang.Class<? extends PlayerService> playerService)
检查 PlayerService 是否存活。
|
boolean |
isStalled() |
static void |
updatePlayerState(android.content.Context context,
java.lang.Class<? extends PlayerService> playerService,
AppWidgetPlayerState playerState) |
void |
writeToParcel(android.os.Parcel dest,
int flags) |
public static final java.lang.String ACTION_PLAYER_STATE_CHANGED
public static final android.os.Parcelable.Creator<AppWidgetPlayerState> CREATOR
public AppWidgetPlayerState(@NonNull PlaybackState playbackState, @Nullable MusicItem playingMusicItem, @NonNull PlayMode playMode, float speed, long playProgress, long playProgressUpdateTime, boolean preparing, boolean prepared, boolean stalled, @NonNull java.lang.String errorMessage)
protected AppWidgetPlayerState(android.os.Parcel in)
public static AppWidgetPlayerState emptyState()
public static AppWidgetPlayerState getPlayerState(@NonNull android.content.Context context, @NonNull java.lang.Class<? extends PlayerService> playerService)
public static void updatePlayerState(@NonNull android.content.Context context, @NonNull java.lang.Class<? extends PlayerService> playerService, @NonNull AppWidgetPlayerState playerState)
@NonNull public PlaybackState getPlaybackState()
@Nullable public MusicItem getPlayingMusicItem()
@NonNull public PlayMode getPlayMode()
public float getSpeed()
public long getPlayProgress()
public long getPlayProgressUpdateTime()
public boolean isPreparing()
public boolean isPrepared()
public boolean isStalled()
@NonNull public java.lang.String getErrorMessage()
public static boolean isServiceAlive(android.content.Context context, java.lang.Class<? extends PlayerService> playerService)
public void writeToParcel(android.os.Parcel dest, int flags)
writeToParcel
在接口中 android.os.Parcelable
public int describeContents()
describeContents
在接口中 android.os.Parcelable