Merge pull request #4993 from ByteHamster/remove-metadata-loader-from-model
Removed metadata loader from model
This commit is contained in:
commit
1828dd1622
@ -19,13 +19,11 @@ import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
|
|||||||
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
|
||||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
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.DBWriter;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||||
import de.danoeh.antennapod.core.sync.SyncService;
|
import de.danoeh.antennapod.core.sync.SyncService;
|
||||||
import de.danoeh.antennapod.core.sync.model.EpisodeAction;
|
import de.danoeh.antennapod.core.sync.model.EpisodeAction;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlayableException;
|
|
||||||
|
|
||||||
public class FeedMedia extends FeedFile implements Playable {
|
public class FeedMedia extends FeedFile implements Playable {
|
||||||
private static final String TAG = "FeedMedia";
|
private static final String TAG = "FeedMedia";
|
||||||
@ -383,13 +381,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
prefEditor.putLong(PREF_MEDIA_ID, id);
|
prefEditor.putLong(PREF_MEDIA_ID, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadMetadata() throws PlayableException {
|
|
||||||
if (item == null && itemID != 0) {
|
|
||||||
item = DBReader.getFeedItem(itemID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEpisodeTitle() {
|
public String getEpisodeTitle() {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
@ -441,14 +432,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
return download_url;
|
return download_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPaymentLink() {
|
|
||||||
if (item == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return item.getPaymentLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getPubDate() {
|
public Date getPubDate() {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
@ -466,11 +449,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
return isDownloaded() && file_url != null;
|
return isDownloaded() && file_url != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean streamAvailable() {
|
|
||||||
return download_url != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getItemId() {
|
public long getItemId() {
|
||||||
return itemID;
|
return itemID;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import android.view.SurfaceHolder;
|
|||||||
import androidx.media.AudioAttributesCompat;
|
import androidx.media.AudioAttributesCompat;
|
||||||
import androidx.media.AudioFocusRequestCompat;
|
import androidx.media.AudioFocusRequestCompat;
|
||||||
import androidx.media.AudioManagerCompat;
|
import androidx.media.AudioManagerCompat;
|
||||||
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import org.antennapod.audio.MediaPlayer;
|
import org.antennapod.audio.MediaPlayer;
|
||||||
|
|
||||||
import java.io.File;
|
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.AudioPlayer;
|
||||||
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
import de.danoeh.antennapod.core.util.playback.IPlayer;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
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.PlaybackServiceStarter;
|
||||||
import de.danoeh.antennapod.core.util.playback.VideoPlayer;
|
import de.danoeh.antennapod.core.util.playback.VideoPlayer;
|
||||||
|
|
||||||
@ -259,7 +259,9 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||||||
LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
|
LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
|
||||||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||||
try {
|
try {
|
||||||
media.loadMetadata();
|
if (media instanceof FeedMedia && ((FeedMedia) media).getItem() == null) {
|
||||||
|
((FeedMedia) media).setItem(DBReader.getFeedItem(((FeedMedia) media).getItemId()));
|
||||||
|
}
|
||||||
callback.onMediaChanged(false);
|
callback.onMediaChanged(false);
|
||||||
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
|
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
|
||||||
if (stream) {
|
if (stream) {
|
||||||
@ -289,7 +291,7 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||||||
onPrepared(startWhenPrepared);
|
onPrepared(startWhenPrepared);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (PlayableException | IOException | IllegalStateException e) {
|
} catch (IOException | IllegalStateException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
setPlayerStatus(PlayerStatus.ERROR, null);
|
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.NetworkUtils;
|
||||||
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
|
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
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.PlayableUtils;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
import de.danoeh.antennapod.core.util.playback.PlaybackServiceStarter;
|
||||||
import de.danoeh.antennapod.core.widget.WidgetUpdater;
|
import de.danoeh.antennapod.core.widget.WidgetUpdater;
|
||||||
@ -993,11 +992,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||||||
}
|
}
|
||||||
Log.d(TAG, "getNextInQueue()");
|
Log.d(TAG, "getNextInQueue()");
|
||||||
FeedMedia media = (FeedMedia) currentMedia;
|
FeedMedia media = (FeedMedia) currentMedia;
|
||||||
try {
|
if (media.getItem() == null) {
|
||||||
media.loadMetadata();
|
media.setItem(DBReader.getFeedItem(media.getItemId()));
|
||||||
} catch (PlayableException e) {
|
|
||||||
Log.e(TAG, "Unable to load metadata to get next in queue", e);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
FeedItem item = media.getItem();
|
FeedItem item = media.getItem();
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
* 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 {
|
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
|
* 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);
|
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
|
* Returns the title of the episode that this playable represents
|
||||||
*/
|
*/
|
||||||
@ -47,8 +39,6 @@ public interface Playable extends Parcelable {
|
|||||||
*/
|
*/
|
||||||
String getWebsiteLink();
|
String getWebsiteLink();
|
||||||
|
|
||||||
String getPaymentLink();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title of the feed this Playable belongs to.
|
* Returns the title of the feed this Playable belongs to.
|
||||||
*/
|
*/
|
||||||
@ -89,8 +79,7 @@ public interface Playable extends Parcelable {
|
|||||||
String getDescription();
|
String getDescription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of media. This method should return the correct value
|
* Returns the type of media.
|
||||||
* BEFORE loadMetadata() is called.
|
|
||||||
*/
|
*/
|
||||||
MediaType getMediaType();
|
MediaType getMediaType();
|
||||||
|
|
||||||
@ -112,12 +101,6 @@ public interface Playable extends Parcelable {
|
|||||||
*/
|
*/
|
||||||
boolean localFileAvailable();
|
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
|
* Saves the current position of this object. Implementations can use the
|
||||||
* provided SharedPreference to save this information and retrieve it later
|
* 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.
|
//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
|
@Override
|
||||||
public String getEpisodeTitle() {
|
public String getEpisodeTitle() {
|
||||||
return episodeTitle;
|
return episodeTitle;
|
||||||
@ -145,11 +140,6 @@ public class RemoteMedia implements Playable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPaymentLink() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFeedTitle() {
|
public String getFeedTitle() {
|
||||||
return feedTitle;
|
return feedTitle;
|
||||||
@ -195,11 +185,6 @@ public class RemoteMedia implements Playable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean streamAvailable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timestamp) {
|
public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timestamp) {
|
||||||
//we're not saving playback information for this kind of items on preferences
|
//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.cast.MediaMetadata;
|
||||||
import com.google.android.gms.common.images.WebImage;
|
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 de.danoeh.antennapod.core.util.playback.RemoteMedia;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
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.
|
* 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
|
* Before using this method, one should make sure {@link #isCastable(Playable)} returns
|
||||||
* {@code true}.
|
* {@code true}. This method should not run on the main thread.
|
||||||
*
|
|
||||||
* Unless media.{@link FeedMedia#loadMetadata() loadMetadata()} has already been called,
|
|
||||||
* this method should not run on the main thread.
|
|
||||||
*
|
*
|
||||||
* @param media The {@link FeedMedia} object to be converted.
|
* @param media The {@link FeedMedia} object to be converted.
|
||||||
* @return {@link MediaInfo} object in a format proper for casting.
|
* @return {@link MediaInfo} object in a format proper for casting.
|
||||||
*/
|
*/
|
||||||
public static MediaInfo convertFromFeedMedia(FeedMedia media){
|
public static MediaInfo convertFromFeedMedia(FeedMedia media){
|
||||||
if(media == null) {
|
if (media == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
|
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_GENERIC);
|
||||||
try{
|
if (media.getItem() == null) {
|
||||||
media.loadMetadata();
|
media.setItem(DBReader.getFeedItem(media.getItemId()));
|
||||||
} catch (PlayableException e) {
|
|
||||||
Log.e(TAG, "Unable to load FeedMedia metadata", e);
|
|
||||||
}
|
}
|
||||||
FeedItem feedItem = media.getItem();
|
FeedItem feedItem = media.getItem();
|
||||||
if (feedItem != null) {
|
if (feedItem != null) {
|
||||||
@ -188,16 +182,11 @@ public class CastUtils {
|
|||||||
if (mediaId > 0) {
|
if (mediaId > 0) {
|
||||||
FeedMedia fMedia = DBReader.getFeedMedia(mediaId);
|
FeedMedia fMedia = DBReader.getFeedMedia(mediaId);
|
||||||
if (fMedia != null) {
|
if (fMedia != null) {
|
||||||
try {
|
if (matches(media, fMedia)) {
|
||||||
fMedia.loadMetadata();
|
result = fMedia;
|
||||||
if (matches(media, fMedia)) {
|
Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
|
||||||
result = fMedia;
|
} else {
|
||||||
Log.d(TAG, "FeedMedia object obtained matches the MediaInfo provided. id=" + mediaId);
|
Log.d(TAG, "FeedMedia object obtained does NOT match 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);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Unable to find in database a FeedMedia with id=" + mediaId);
|
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.CastManager;
|
||||||
import de.danoeh.antennapod.core.cast.CastUtils;
|
import de.danoeh.antennapod.core.cast.CastUtils;
|
||||||
import de.danoeh.antennapod.core.cast.DefaultCastConsumer;
|
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.util.playback.RemoteMedia;
|
||||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||||
import de.danoeh.antennapod.core.feed.MediaType;
|
import de.danoeh.antennapod.core.feed.MediaType;
|
||||||
@ -354,16 +354,13 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||||||
this.mediaType = media.getMediaType();
|
this.mediaType = media.getMediaType();
|
||||||
this.startWhenPrepared.set(startWhenPrepared);
|
this.startWhenPrepared.set(startWhenPrepared);
|
||||||
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
setPlayerStatus(PlayerStatus.INITIALIZING, media);
|
||||||
try {
|
if (media instanceof FeedMedia && ((FeedMedia) media).getItem() == null) {
|
||||||
media.loadMetadata();
|
((FeedMedia) media).setItem(DBReader.getFeedItem(((FeedMedia) media).getItemId()));
|
||||||
callback.onMediaChanged(true);
|
}
|
||||||
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
callback.onMediaChanged(true);
|
||||||
if (prepareImmediately) {
|
setPlayerStatus(PlayerStatus.INITIALIZED, media);
|
||||||
prepare();
|
if (prepareImmediately) {
|
||||||
}
|
prepare();
|
||||||
} catch (PlayableException e) {
|
|
||||||
Log.e(TAG, "Error while loading media metadata", e);
|
|
||||||
setPlayerStatus(PlayerStatus.STOPPED, null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user