Removed metadata loader from model
This commit is contained in:
parent
dd0502c0d6
commit
bc073ff38f
|
@ -19,13 +19,11 @@ import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
|||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.sync.SyncService;
|
||||
import de.danoeh.antennapod.core.sync.model.EpisodeAction;
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
||||
|
||||
public class FeedMedia extends FeedFile implements Playable {
|
||||
private static final String TAG = "FeedMedia";
|
||||
|
@ -383,13 +381,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
prefEditor.putLong(PREF_MEDIA_ID, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMetadata() throws PlayableException {
|
||||
if (item == null && itemID != 0) {
|
||||
item = DBReader.getFeedItem(itemID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEpisodeTitle() {
|
||||
if (item == null) {
|
||||
|
@ -441,14 +432,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
return download_url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPaymentLink() {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
return item.getPaymentLink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getPubDate() {
|
||||
if (item == null) {
|
||||
|
@ -466,11 +449,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
return isDownloaded() && file_url != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean streamAvailable() {
|
||||
return download_url != null;
|
||||
}
|
||||
|
||||
public long getItemId() {
|
||||
return itemID;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.view.SurfaceHolder;
|
|||
import androidx.media.AudioAttributesCompat;
|
||||
import androidx.media.AudioFocusRequestCompat;
|
||||
import androidx.media.AudioManagerCompat;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import org.antennapod.audio.MediaPlayer;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -38,7 +39,6 @@ import de.danoeh.antennapod.core.util.RewindAfterPauseUtils;
|
|||
import de.danoeh.antennapod.core.util.playback.AudioPlayer;
|
||||
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.danoeh.antennapod.core.util.playback.VideoPlayer;
|
||||
|
||||
|
@ -259,7 +259,9 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
|
||||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||
try {
|
||||
media.loadMetadata();
|
||||
if (media instanceof FeedMedia && ((FeedMedia) media).getItem() == null) {
|
||||
((FeedMedia) media).setItem(DBReader.getFeedItem(((FeedMedia) media).getItemId()));
|
||||
}
|
||||
callback.onMediaChanged(false);
|
||||
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
|
||||
if (stream) {
|
||||
|
@ -289,7 +291,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
onPrepared(startWhenPrepared);
|
||||
}
|
||||
|
||||
} catch (PlayableException | IOException | IllegalStateException e) {
|
||||
} catch (IOException | IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
setPlayerStatus(PlayerStatus.ERROR, null);
|
||||
}
|
||||
|
|
|
@ -77,7 +77,6 @@ import de.danoeh.antennapod.core.util.IntentUtils;
|
|||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||
import de.danoeh.antennapod.core.widget.WidgetUpdater;
|
||||
|
@ -993,11 +992,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
Log.d(TAG, "getNextInQueue()");
|
||||
FeedMedia media = (FeedMedia) currentMedia;
|
||||
try {
|
||||
media.loadMetadata();
|
||||
} catch (PlayableException e) {
|
||||
Log.e(TAG, "Unable to load metadata to get next in queue", e);
|
||||
return null;
|
||||
if (media.getItem() == null) {
|
||||
media.setItem(DBReader.getFeedItem(media.getItemId()));
|
||||
}
|
||||
FeedItem item = media.getItem();
|
||||
if (item == null) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||
* Interface for objects that can be played by the PlaybackService.
|
||||
*/
|
||||
public interface Playable extends Parcelable {
|
||||
public static final int INVALID_TIME = -1;
|
||||
int INVALID_TIME = -1;
|
||||
|
||||
/**
|
||||
* Save information about the playable in a preference so that it can be
|
||||
|
@ -24,14 +24,6 @@ public interface Playable extends Parcelable {
|
|||
*/
|
||||
void writeToPreferences(SharedPreferences.Editor prefEditor);
|
||||
|
||||
/**
|
||||
* This method is called from a separate thread by the PlaybackService.
|
||||
* Playable objects should load their metadata in this method. This method
|
||||
* should execute as quickly as possible and NOT load chapter marks if no
|
||||
* local file is available.
|
||||
*/
|
||||
void loadMetadata() throws PlayableException;
|
||||
|
||||
/**
|
||||
* Returns the title of the episode that this playable represents
|
||||
*/
|
||||
|
@ -47,8 +39,6 @@ public interface Playable extends Parcelable {
|
|||
*/
|
||||
String getWebsiteLink();
|
||||
|
||||
String getPaymentLink();
|
||||
|
||||
/**
|
||||
* Returns the title of the feed this Playable belongs to.
|
||||
*/
|
||||
|
@ -89,8 +79,7 @@ public interface Playable extends Parcelable {
|
|||
String getDescription();
|
||||
|
||||
/**
|
||||
* Returns the type of media. This method should return the correct value
|
||||
* BEFORE loadMetadata() is called.
|
||||
* Returns the type of media.
|
||||
*/
|
||||
MediaType getMediaType();
|
||||
|
||||
|
@ -112,12 +101,6 @@ public interface Playable extends Parcelable {
|
|||
*/
|
||||
boolean localFileAvailable();
|
||||
|
||||
/**
|
||||
* Returns true if a streamable file is available. getStreamUrl MUST return
|
||||
* a non-null string if this method returns true.
|
||||
*/
|
||||
boolean streamAvailable();
|
||||
|
||||
/**
|
||||
* Saves the current position of this object. Implementations can use the
|
||||
* provided SharedPreference to save this information and retrieve it later
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package de.danoeh.antennapod.core.util.playback;
|
||||
|
||||
/**
|
||||
* Exception thrown by {@link Playable} implementations.
|
||||
*/
|
||||
public class PlayableException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public PlayableException(String detailMessage) {
|
||||
super(detailMessage);
|
||||
}
|
||||
}
|
|
@ -121,11 +121,6 @@ public class RemoteMedia implements Playable {
|
|||
//it seems pointless to do it, since the session should be kept by the remote device.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMetadata() throws PlayableException {
|
||||
//Already loaded
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEpisodeTitle() {
|
||||
return episodeTitle;
|
||||
|
@ -145,11 +140,6 @@ public class RemoteMedia implements Playable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPaymentLink() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFeedTitle() {
|
||||
return feedTitle;
|
||||
|
@ -195,11 +185,6 @@ public class RemoteMedia implements Playable {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean streamAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timestamp) {
|
||||
//we're not saving playback information for this kind of items on preferences
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.google.android.gms.cast.MediaInfo;
|
|||
import com.google.android.gms.cast.MediaMetadata;
|
||||
import com.google.android.gms.common.images.WebImage;
|
||||
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
||||
import de.danoeh.antennapod.core.util.playback.RemoteMedia;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
@ -78,23 +77,18 @@ public class CastUtils {
|
|||
/**
|
||||
* Converts {@link FeedMedia} objects into a format suitable for sending to a Cast Device.
|
||||
* Before using this method, one should make sure {@link #isCastable(Playable)} returns
|
||||
* {@code true}.
|
||||
*
|
||||
* Unless media.{@link FeedMedia#loadMetadata() loadMetadata()} has already been called,
|
||||
* this method should not run on the main thread.
|
||||
* {@code true}. This method should not run on the main thread.
|
||||
*
|
||||
* @param media The {@link FeedMedia} object to be converted.
|
||||
* @return {@link MediaInfo} object in a format proper for casting.
|
||||
*/
|
||||
public static MediaInfo convertFromFeedMedia(FeedMedia media){
|
||||
if(media == null) {
|
||||
if (media == null) {
|
||||
return null;
|
||||
}
|
||||
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
|
||||
try{
|
||||
media.loadMetadata();
|
||||
} catch (PlayableException e) {
|
||||
Log.e(TAG, "Unable to load FeedMedia metadata", e);
|
||||
if (media.getItem() == null) {
|
||||
media.setItem(DBReader.getFeedItem(media.getItemId()));
|
||||
}
|
||||
FeedItem feedItem = media.getItem();
|
||||
if (feedItem != null) {
|
||||
|
@ -188,16 +182,11 @@ public class CastUtils {
|
|||
if (mediaId > 0) {
|
||||
FeedMedia fMedia = DBReader.getFeedMedia(mediaId);
|
||||
if (fMedia != null) {
|
||||
try {
|
||||
fMedia.loadMetadata();
|
||||
if (matches(media, fMedia)) {
|
||||
result = fMedia;
|
||||
Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
|
||||
} else {
|
||||
Log.d(TAG, "FeedMedia object obtained does NOT match the MediaInfo provided. id=" + mediaId);
|
||||
}
|
||||
} catch (PlayableException e) {
|
||||
Log.e(TAG, "Unable to load FeedMedia metadata to compare with MediaInfo", e);
|
||||
if (matches(media, fMedia)) {
|
||||
result = fMedia;
|
||||
Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
|
||||
} else {
|
||||
Log.d(TAG, "FeedMedia object obtained does NOT match the MediaInfo provided. id=" + mediaId);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Unable to find in database a FeedMedia with id=" + mediaId);
|
||||
|
|
|
@ -28,7 +28,7 @@ import de.danoeh.antennapod.core.cast.CastConsumer;
|
|||
import de.danoeh.antennapod.core.cast.CastManager;
|
||||
import de.danoeh.antennapod.core.cast.CastUtils;
|
||||
import de.danoeh.antennapod.core.cast.DefaultCastConsumer;
|
||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.util.playback.RemoteMedia;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
|
@ -354,16 +354,13 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
this.mediaType = media.getMediaType();
|
||||
this.startWhenPrepared.set(startWhenPrepared);
|
||||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||
try {
|
||||
media.loadMetadata();
|
||||
callback.onMediaChanged(true);
|
||||
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
||||
if (prepareImmediately) {
|
||||
prepare();
|
||||
}
|
||||
} catch (PlayableException e) {
|
||||
Log.e(TAG, "Error while loading media metadata", e);
|
||||
setPlayerStatus(PlayerStatus.STOPPED, null);
|
||||
if (media instanceof FeedMedia && ((FeedMedia) media).getItem() == null) {
|
||||
((FeedMedia) media).setItem(DBReader.getFeedItem(((FeedMedia) media).getItemId()));
|
||||
}
|
||||
callback.onMediaChanged(true);
|
||||
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
||||
if (prepareImmediately) {
|
||||
prepare();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue