use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class PlaybackService method getNextInQueue.
private Playable getNextInQueue(final Playable currentMedia) {
if (!(currentMedia instanceof FeedMedia)) {
Log.d(TAG, "getNextInQueue(), but playable not an instance of FeedMedia, so not proceeding");
PlaybackPreferences.writeNoMediaPlaying();
return null;
}
Log.d(TAG, "getNextInQueue()");
FeedMedia media = (FeedMedia) currentMedia;
if (media.getItem() == null) {
media.setItem(DBReader.getFeedItem(media.getItemId()));
}
FeedItem item = media.getItem();
if (item == null) {
Log.w(TAG, "getNextInQueue() with FeedMedia object whose FeedItem is null");
PlaybackPreferences.writeNoMediaPlaying();
return null;
}
FeedItem nextItem;
nextItem = DBReader.getNextInQueue(item);
if (nextItem == null || nextItem.getMedia() == null) {
PlaybackPreferences.writeNoMediaPlaying();
return null;
}
if (!UserPreferences.isFollowQueue()) {
Log.d(TAG, "getNextInQueue(), but follow queue is not enabled.");
PlaybackPreferences.writeMediaPlaying(nextItem.getMedia(), PlayerStatus.STOPPED, false);
updateNotificationAndMediaSession(nextItem.getMedia());
return null;
}
if (!nextItem.getMedia().localFileAvailable() && !NetworkUtils.isStreamingAllowed() && UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
displayStreamingNotAllowedNotification(new PlaybackServiceStarter(this, nextItem.getMedia()).prepareImmediately(true).startWhenPrepared(true).shouldStream(true).getIntent());
PlaybackPreferences.writeNoMediaPlaying();
stateManager.stopService();
return null;
}
return nextItem.getMedia();
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class PlaybackService method skipIntro.
private void skipIntro(Playable playable) {
if (!(playable instanceof FeedMedia)) {
return;
}
FeedMedia feedMedia = (FeedMedia) playable;
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
int skipIntro = preferences.getFeedSkipIntro();
Context context = getApplicationContext();
if (skipIntro > 0 && playable.getPosition() < skipIntro * 1000) {
int duration = getDuration();
if (skipIntro * 1000 < duration || duration <= 0) {
Log.d(TAG, "skipIntro " + playable.getEpisodeTitle());
mediaPlayer.seekTo(skipIntro * 1000);
String skipIntroMesg = context.getString(R.string.pref_feed_skip_intro_toast, skipIntro);
Toast toast = Toast.makeText(context, skipIntroMesg, Toast.LENGTH_LONG);
toast.show();
}
}
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class LocalPSMP method playMediaObject.
/**
* Internal implementation of playMediaObject. This method has an additional parameter that allows the caller to force a media player reset even if
* the given playable parameter is the same object as the currently playing media.
* <p/>
* This method requires the playerLock and is executed on the caller's thread.
*
* @see #playMediaObject(Playable, boolean, boolean, boolean)
*/
private void playMediaObject(@NonNull final Playable playable, final boolean forceReset, final boolean stream, final boolean startWhenPrepared, final boolean prepareImmediately) {
if (!playerLock.isHeldByCurrentThread()) {
throw new IllegalStateException("method requires playerLock");
}
if (media != null) {
if (!forceReset && media.getIdentifier().equals(playable.getIdentifier()) && playerStatus == PlayerStatus.PLAYING) {
// episode is already playing -> ignore method call
Log.d(TAG, "Method call to playMediaObject was ignored: media file already playing.");
return;
} else {
// stop playback of this episode
if (playerStatus == PlayerStatus.PAUSED || playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARED) {
mediaPlayer.stop();
}
// set temporarily to pause in order to update list with current position
if (playerStatus == PlayerStatus.PLAYING) {
callback.onPlaybackPause(media, getPosition());
}
if (!media.getIdentifier().equals(playable.getIdentifier())) {
final Playable oldMedia = media;
executor.submit(() -> callback.onPostPlayback(oldMedia, false, false, true));
}
setPlayerStatus(PlayerStatus.INDETERMINATE, null);
}
}
this.media = playable;
this.stream = stream;
this.mediaType = media.getMediaType();
this.videoSize = null;
createMediaPlayer();
LocalPSMP.this.startWhenPrepared.set(startWhenPrepared);
setPlayerStatus(PlayerStatus.INITIALIZING, media);
try {
callback.ensureMediaInfoLoaded(media);
callback.onMediaChanged(false);
setPlaybackParams(PlaybackSpeedUtils.getCurrentPlaybackSpeed(media), UserPreferences.isSkipSilence());
if (stream) {
if (playable instanceof FeedMedia) {
FeedMedia feedMedia = (FeedMedia) playable;
FeedPreferences preferences = feedMedia.getItem().getFeed().getPreferences();
mediaPlayer.setDataSource(media.getStreamUrl(), preferences.getUsername(), preferences.getPassword());
} else {
mediaPlayer.setDataSource(media.getStreamUrl());
}
} else if (media.getLocalMediaUrl() != null && new File(media.getLocalMediaUrl()).canRead()) {
mediaPlayer.setDataSource(media.getLocalMediaUrl());
} else {
throw new IOException("Unable to read local file " + media.getLocalMediaUrl());
}
UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() != Configuration.UI_MODE_TYPE_CAR) {
setPlayerStatus(PlayerStatus.INITIALIZED, media);
}
if (prepareImmediately) {
setPlayerStatus(PlayerStatus.PREPARING, media);
mediaPlayer.prepare();
onPrepared(startWhenPrepared);
}
} catch (IOException | IllegalStateException e) {
e.printStackTrace();
setPlayerStatus(PlayerStatus.ERROR, null);
EventBus.getDefault().postSticky(new PlayerErrorEvent(e.getLocalizedMessage()));
}
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class LocalFeedUpdater method createFeedItem.
private static FeedItem createFeedItem(Feed feed, DocumentFile file, Context context) {
FeedItem item = new FeedItem(0, file.getName(), UUID.randomUUID().toString(), file.getName(), new Date(file.lastModified()), FeedItem.UNPLAYED, feed);
item.disableAutoDownload();
long size = file.length();
FeedMedia media = new FeedMedia(0, item, 0, 0, size, file.getType(), file.getUri().toString(), file.getUri().toString(), false, null, 0, 0);
item.setMedia(media);
try {
loadMetadata(item, file, context);
} catch (Exception e) {
item.setDescriptionIfLonger(e.getMessage());
}
return item;
}
use of de.danoeh.antennapod.model.feed.FeedMedia in project AntennaPod by AntennaPod.
the class DownloadService method enqueueFeedItems.
private void enqueueFeedItems(@NonNull List<DownloadRequest> requests) {
List<FeedItem> feedItems = new ArrayList<>();
for (DownloadRequest request : requests) {
if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
long mediaId = request.getFeedfileId();
FeedMedia media = DBReader.getFeedMedia(mediaId);
if (media == null) {
Log.w(TAG, "enqueueFeedItems() : FeedFile Id " + mediaId + " is not found. ignore it.");
continue;
}
feedItems.add(media.getItem());
}
}
List<FeedItem> actuallyEnqueued = Collections.emptyList();
try {
actuallyEnqueued = DBTasks.enqueueFeedItemsToDownload(getApplicationContext(), feedItems);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
for (DownloadRequest request : requests) {
if (request.getFeedfileType() != FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
continue;
}
final long mediaId = request.getFeedfileId();
for (FeedItem item : actuallyEnqueued) {
if (item.getMedia() != null && item.getMedia().getId() == mediaId) {
request.setMediaEnqueued(true);
}
}
}
}
Aggregations