Ported PlaybackController to DB*-classes
This commit is contained in:
parent
e28229a29c
commit
9f36cecf4b
@ -4,6 +4,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import de.danoeh.antennapod.storage.DBReader;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
@ -13,11 +15,12 @@ import android.util.Log;
|
||||
import de.danoeh.antennapod.asynctask.ImageLoader;
|
||||
import de.danoeh.antennapod.feed.Chapter;
|
||||
import de.danoeh.antennapod.feed.Feed;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.feed.MediaType;
|
||||
|
||||
/** Interface for objects that can be played by the PlaybackService. */
|
||||
/**
|
||||
* Interface for objects that can be played by the PlaybackService.
|
||||
*/
|
||||
public interface Playable extends Parcelable,
|
||||
ImageLoader.ImageWorkerTaskResource {
|
||||
|
||||
@ -44,7 +47,9 @@ public interface Playable extends Parcelable,
|
||||
*/
|
||||
public void loadChapterMarks();
|
||||
|
||||
/** Returns the title of the episode that this playable represents */
|
||||
/**
|
||||
* Returns the title of the episode that this playable represents
|
||||
*/
|
||||
public String getEpisodeTitle();
|
||||
|
||||
/**
|
||||
@ -59,12 +64,16 @@ public interface Playable extends Parcelable,
|
||||
*/
|
||||
public List<Chapter> getChapters();
|
||||
|
||||
/** Returns a link to a website that is meant to be shown in a browser */
|
||||
/**
|
||||
* Returns a link to a website that is meant to be shown in a browser
|
||||
*/
|
||||
public String getWebsiteLink();
|
||||
|
||||
public String getPaymentLink();
|
||||
|
||||
/** Returns the title of the feed this Playable belongs to. */
|
||||
/**
|
||||
* Returns the title of the feed this Playable belongs to.
|
||||
*/
|
||||
public String getFeedTitle();
|
||||
|
||||
/**
|
||||
@ -73,10 +82,14 @@ public interface Playable extends Parcelable,
|
||||
*/
|
||||
public Object getIdentifier();
|
||||
|
||||
/** Return duration of object or 0 if duration is unknown. */
|
||||
/**
|
||||
* Return duration of object or 0 if duration is unknown.
|
||||
*/
|
||||
public int getDuration();
|
||||
|
||||
/** Return position of object or 0 if position is unknown. */
|
||||
/**
|
||||
* Return position of object or 0 if position is unknown.
|
||||
*/
|
||||
public int getPosition();
|
||||
|
||||
/**
|
||||
@ -120,10 +133,14 @@ public interface Playable extends Parcelable,
|
||||
|
||||
public void setDuration(int newDuration);
|
||||
|
||||
/** Is called by the PlaybackService when playback starts. */
|
||||
/**
|
||||
* Is called by the PlaybackService when playback starts.
|
||||
*/
|
||||
public void onPlaybackStart();
|
||||
|
||||
/** Is called by the PlaybackService when playback is completed. */
|
||||
/**
|
||||
* Is called by the PlaybackService when playback is completed.
|
||||
*/
|
||||
public void onPlaybackCompleted();
|
||||
|
||||
/**
|
||||
@ -135,34 +152,30 @@ public interface Playable extends Parcelable,
|
||||
|
||||
public void setChapters(List<Chapter> chapters);
|
||||
|
||||
/** Provides utility methods for Playable objects. */
|
||||
/**
|
||||
* Provides utility methods for Playable objects.
|
||||
*/
|
||||
public static class PlayableUtils {
|
||||
private static final String TAG = "PlayableUtils";
|
||||
|
||||
/**
|
||||
* Restores a playable object from a sharedPreferences file.
|
||||
* Restores a playable object from a sharedPreferences file. This method might load data from the database,
|
||||
* depending on the type of playable that was restored.
|
||||
*
|
||||
* @param type
|
||||
* An integer that represents the type of the Playable object
|
||||
* @param type An integer that represents the type of the Playable object
|
||||
* that is restored.
|
||||
* @param pref
|
||||
* The SharedPreferences file from which the Playable object
|
||||
* @param pref The SharedPreferences file from which the Playable object
|
||||
* is restored
|
||||
* @return The restored Playable object
|
||||
*/
|
||||
public static Playable createInstanceFromPreferences(int type,
|
||||
public static Playable createInstanceFromPreferences(Context context, int type,
|
||||
SharedPreferences pref) {
|
||||
// ADD new Playable types here:
|
||||
switch (type) {
|
||||
case FeedMedia.PLAYABLE_TYPE_FEEDMEDIA:
|
||||
long feedId = pref.getLong(FeedMedia.PREF_FEED_ID, -1);
|
||||
long mediaId = pref.getLong(FeedMedia.PREF_MEDIA_ID, -1);
|
||||
if (feedId != -1 && mediaId != -1) {
|
||||
Feed feed = FeedManager.getInstance().getFeed(feedId);
|
||||
if (feed != null) {
|
||||
return FeedManager.getInstance().getFeedMedia(mediaId,
|
||||
feed);
|
||||
}
|
||||
if (mediaId != -1) {
|
||||
return DBReader.getFeedMedia(context, mediaId);
|
||||
}
|
||||
break;
|
||||
case ExternalMedia.PLAYABLE_TYPE_EXTERNAL_MEDIA:
|
||||
@ -207,7 +220,9 @@ public interface Playable extends Parcelable,
|
||||
void onShownotesLoaded(String shownotes);
|
||||
}
|
||||
|
||||
/** Uses local file as image resource if it is available. */
|
||||
/**
|
||||
* Uses local file as image resource if it is available.
|
||||
*/
|
||||
public static class DefaultPlayableImageLoader implements
|
||||
ImageLoader.ImageWorkerTaskResource {
|
||||
private Playable playable;
|
||||
|
@ -16,6 +16,7 @@ import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
@ -28,7 +29,6 @@ import android.widget.TextView;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.feed.Chapter;
|
||||
import de.danoeh.antennapod.feed.FeedManager;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.service.PlaybackService;
|
||||
@ -88,7 +88,8 @@ public abstract class PlaybackController {
|
||||
Log.w(TAG,
|
||||
"Rejected execution of runnable in schedExecutor");
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,7 +152,9 @@ public abstract class PlaybackController {
|
||||
|
||||
}
|
||||
|
||||
/** Should be called in the activity's onPause() method. */
|
||||
/**
|
||||
* Should be called in the activity's onPause() method.
|
||||
*/
|
||||
public void pause() {
|
||||
mediaInfoLoaded = false;
|
||||
if (playbackService != null && playbackService.isPlayingVideo()) {
|
||||
@ -167,7 +170,14 @@ public abstract class PlaybackController {
|
||||
private void bindToService() {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Trying to connect to service");
|
||||
Intent serviceIntent = getPlayLastPlayedMediaIntent();
|
||||
AsyncTask<Void, Void, Intent> intentLoader = new AsyncTask<Void, Void, Intent>() {
|
||||
@Override
|
||||
protected Intent doInBackground(Void... voids) {
|
||||
return getPlayLastPlayedMediaIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Intent serviceIntent) {
|
||||
boolean bound = false;
|
||||
if (!PlaybackService.isRunning) {
|
||||
if (serviceIntent != null) {
|
||||
@ -188,6 +198,9 @@ public abstract class PlaybackController {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Result for service binding: " + bound);
|
||||
}
|
||||
};
|
||||
intentLoader.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an intent that starts the PlaybackService and plays the last
|
||||
@ -201,7 +214,7 @@ public abstract class PlaybackController {
|
||||
long currentlyPlayingMedia = PlaybackPreferences
|
||||
.getCurrentlyPlayingMedia();
|
||||
if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
|
||||
Playable media = PlayableUtils.createInstanceFromPreferences(
|
||||
Playable media = PlayableUtils.createInstanceFromPreferences(activity,
|
||||
(int) currentlyPlayingMedia, prefs);
|
||||
if (media != null) {
|
||||
Intent serviceIntent = new Intent(activity,
|
||||
@ -358,7 +371,9 @@ public abstract class PlaybackController {
|
||||
|
||||
public abstract void onShutdownNotification();
|
||||
|
||||
/** Called when the currently displayed information should be refreshed. */
|
||||
/**
|
||||
* Called when the currently displayed information should be refreshed.
|
||||
*/
|
||||
public abstract void onReloadNotification(int code);
|
||||
|
||||
public abstract void onBufferStart();
|
||||
@ -669,7 +684,9 @@ public abstract class PlaybackController {
|
||||
}
|
||||
}
|
||||
|
||||
/** Move service into INITIALIZED state if it's paused to save bandwidth */
|
||||
/**
|
||||
* Move service into INITIALIZED state if it's paused to save bandwidth
|
||||
*/
|
||||
public void reinitServiceIfPaused() {
|
||||
if (playbackService != null
|
||||
&& playbackService.isShouldStream()
|
||||
@ -680,7 +697,9 @@ public abstract class PlaybackController {
|
||||
}
|
||||
}
|
||||
|
||||
/** Refreshes the current position of the media file that is playing. */
|
||||
/**
|
||||
* Refreshes the current position of the media file that is playing.
|
||||
*/
|
||||
public class MediaPositionObserver implements Runnable {
|
||||
|
||||
public static final int WAITING_INTERVALL = 1000;
|
||||
|
Loading…
x
Reference in New Issue
Block a user