diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
index 123f66661..3ddf3ed74 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java
@@ -1,6 +1,7 @@
package de.danoeh.antennapod.activity;
import android.content.Intent;
+import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.util.Log;
@@ -41,7 +42,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, false);
launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY,
true);
- startService(launchIntent);
+ ContextCompat.startForegroundService(this, launchIntent);
} else if (PlaybackService.isCasting()) {
Intent intent = PlaybackService.getPlayerActivityIntent(this);
if (intent.getComponent() != null &&
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
index cb4dae942..c2ea7fc12 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java
@@ -30,6 +30,7 @@ import android.widget.ListView;
import com.bumptech.glide.Glide;
+import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.util.NotificationUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
@@ -741,6 +742,15 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
loadData();
}
+ public void onEventMainThread(ServiceEvent event) {
+ Log.d(TAG, "onEvent(" + event + ")");
+ switch(event.action) {
+ case SERVICE_STARTED:
+ externalPlayerFragment.connectToPlaybackService();
+ break;
+ }
+ }
+
public void onEventMainThread(ProgressEvent event) {
Log.d(TAG, "onEvent(" + event + ")");
switch(event.action) {
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
index 21e375435..116709587 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java
@@ -34,6 +34,7 @@ import com.joanzapata.iconify.fonts.FontAwesomeIcons;
import java.util.Locale;
import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.core.event.ServiceEvent;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@@ -270,6 +271,9 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
controller.release();
}
controller = newPlaybackController();
+ setupGUI();
+ loadMediaInfo();
+ onPositionObserverUpdate();
}
@Override
@@ -608,8 +612,23 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
super.onResume();
Log.d(TAG, "onResume()");
StorageUtils.checkStorageAvailability(this);
- if(controller != null) {
- controller.init();
+ if (controller != null) {
+ if (PlaybackService.isRunning) {
+ controller.init();
+ } else {
+ controller.resumeServiceNotRunning();
+ }
+ }
+ }
+
+ public void onEventMainThread(ServiceEvent event) {
+ Log.d(TAG, "onEvent(" + event + ")");
+ switch(event.action) {
+ case SERVICE_STARTED:
+ if (controller != null) {
+ controller.init();
+ }
+ break;
}
}
@@ -853,6 +872,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
if(controller == null) {
return;
}
+ controller.init();
controller.playPause();
}
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java
index 733f39b63..e91e96a13 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java
@@ -6,6 +6,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.content.ContextCompat;
import android.support.v4.view.WindowCompat;
import android.support.v7.app.ActionBar;
import android.util.Log;
@@ -30,6 +31,7 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
import de.danoeh.antennapod.core.util.gui.PictureInPictureUtil;
import de.danoeh.antennapod.core.util.playback.ExternalMedia;
import de.danoeh.antennapod.core.util.playback.Playable;
+import de.danoeh.antennapod.service.PlayerWidgetService;
import de.danoeh.antennapod.view.AspectRatioVideoView;
import java.lang.ref.WeakReference;
@@ -89,7 +91,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
launchIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM, false);
launchIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY,
true);
- startService(launchIntent);
+ ContextCompat.startForegroundService(this, launchIntent);
} else if (PlaybackService.isCasting()) {
Intent intent = PlaybackService.getPlayerActivityIntent(this);
if (!intent.getComponent().getClassName().equals(VideoplayerActivity.class.getName())) {
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
index 4a53be9dc..31b0ce333 100644
--- a/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
+++ b/app/src/main/java/de/danoeh/antennapod/adapter/DefaultActionButtonCallback.java
@@ -81,9 +81,15 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
}
} else { // media is downloaded
if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
+ if (!PlaybackService.isRunning) {
+ PlaybackService.startService(context, media, true, false);
+ }
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
}
else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
+ if (!PlaybackService.isRunning) {
+ PlaybackService.startService(context, media, true, false);
+ }
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
}
else {
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
index 2705e7402..e75f312d3 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/ExternalPlayerFragment.java
@@ -37,7 +37,6 @@ public class ExternalPlayerFragment extends Fragment {
private ImageButton butPlay;
private TextView mFeedName;
private ProgressBar mProgressBar;
-
private PlaybackController controller;
public ExternalPlayerFragment() {
@@ -83,6 +82,11 @@ public class ExternalPlayerFragment extends Fragment {
controller.playPause();
}
});
+ loadMediaInfo();
+ }
+
+ public void connectToPlaybackService() {
+ controller.init();
}
private PlaybackController setupPlaybackController() {
@@ -123,7 +127,11 @@ public class ExternalPlayerFragment extends Fragment {
@Override
public void onResume() {
super.onResume();
- controller.init();
+ if (PlaybackService.isRunning) {
+ controller.init();
+ } else {
+ controller.resumeServiceNotRunning();
+ }
onPositionObserverUpdate();
}
@@ -164,13 +172,12 @@ public class ExternalPlayerFragment extends Fragment {
private boolean loadMediaInfo() {
Log.d(TAG, "Loading media info");
- if (controller != null && controller.serviceAvailable()) {
+ if (controller != null) {
Playable media = controller.getMedia();
if (media != null) {
txtvTitle.setText(media.getEpisodeTitle());
mFeedName.setText(media.getFeedTitle());
- mProgressBar.setProgress((int)
- ((double) controller.getPosition() / controller.getDuration() * 100));
+ onPositionObserverUpdate();
Glide.with(getActivity())
.load(media.getImageLocation())
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java
index 2d11e9f71..7078eeb63 100644
--- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java
+++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java
@@ -34,6 +34,7 @@ import com.bumptech.glide.Glide;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.widget.IconButton;
+import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.util.NetworkUtils;
import org.apache.commons.lang3.ArrayUtils;
@@ -243,6 +244,9 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
if (item.hasMedia()) {
FeedMedia media = item.getMedia();
if (!media.isDownloaded()) {
+ if (!PlaybackService.isRunning) {
+ PlaybackService.startService(getActivity(), media, true, false);
+ }
DBTasks.playMedia(getActivity(), media, true, true, true);
((MainActivity) getActivity()).dismissChildFragment();
} else {
diff --git a/app/src/main/java/de/danoeh/antennapod/receiver/PlayerWidget.java b/app/src/main/java/de/danoeh/antennapod/receiver/PlayerWidget.java
index a90f0f706..31242f1fd 100644
--- a/app/src/main/java/de/danoeh/antennapod/receiver/PlayerWidget.java
+++ b/app/src/main/java/de/danoeh/antennapod/receiver/PlayerWidget.java
@@ -5,6 +5,7 @@ import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
@@ -60,7 +61,7 @@ public class PlayerWidget extends AppWidgetProvider {
private void startUpdate(Context context) {
Log.d(TAG, "startUpdate() called with: " + "context = [" + context + "]");
- context.startService(new Intent(context, PlayerWidgetService.class));
+ ContextCompat.startForegroundService(context, new Intent(context, PlayerWidgetService.class));
}
private void stopUpdate(Context context) {
diff --git a/app/src/main/res/layout/external_player_fragment.xml b/app/src/main/res/layout/external_player_fragment.xml
index 0efee08db..dc890807c 100644
--- a/app/src/main/res/layout/external_player_fragment.xml
+++ b/app/src/main/res/layout/external_player_fragment.xml
@@ -44,6 +44,7 @@
android:layout_centerVertical="true"
android:contentDescription="@string/pause_label"
android:background="?attr/selectableItemBackground"
+ android:src="?attr/av_play_big"
tools:src="@drawable/ic_play_arrow_white_36dp"/>
Log.e(TAG, Log.getStackTraceString(error)));
}
+ private Playable getMediaFromPreferences() {
+ long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
+ if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
+ activity.getApplicationContext());
+ return PlayableUtils.createInstanceFromPreferences(activity,
+ (int) currentlyPlayingMedia, prefs);
+ }
+ return null;
+ }
+
/**
* Returns an intent that starts the PlaybackService and plays the last
* played media or null if no last played media could be found.
*/
private Intent getPlayLastPlayedMediaIntent() {
Log.d(TAG, "Trying to restore last played media");
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
- activity.getApplicationContext());
- long currentlyPlayingMedia = PlaybackPreferences.getCurrentlyPlayingMedia();
- if (currentlyPlayingMedia != PlaybackPreferences.NO_MEDIA_PLAYING) {
- Playable media = PlayableUtils.createInstanceFromPreferences(activity,
- (int) currentlyPlayingMedia, prefs);
- if (media != null) {
- Intent serviceIntent = new Intent(activity, PlaybackService.class);
- serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
- serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
- serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
- boolean fileExists = media.localFileAvailable();
- boolean lastIsStream = PlaybackPreferences.getCurrentEpisodeIsStream();
- if (!fileExists && !lastIsStream && media instanceof FeedMedia) {
- DBTasks.notifyMissingFeedMediaFile(activity, (FeedMedia) media);
- }
- serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
- lastIsStream || !fileExists);
- return serviceIntent;
+ Playable media = getMediaFromPreferences();
+ if (media != null) {
+ Intent serviceIntent = new Intent(activity, PlaybackService.class);
+ serviceIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
+ serviceIntent.putExtra(PlaybackService.EXTRA_START_WHEN_PREPARED, false);
+ serviceIntent.putExtra(PlaybackService.EXTRA_PREPARE_IMMEDIATELY, true);
+ boolean fileExists = media.localFileAvailable();
+ boolean lastIsStream = PlaybackPreferences.getCurrentEpisodeIsStream();
+ if (!fileExists && !lastIsStream && media instanceof FeedMedia) {
+ DBTasks.notifyMissingFeedMediaFile(activity, (FeedMedia) media);
}
+ serviceIntent.putExtra(PlaybackService.EXTRA_SHOULD_STREAM,
+ lastIsStream || !fileExists);
+ return serviceIntent;
}
Log.d(TAG, "No last played media found");
return null;
@@ -511,7 +522,7 @@ public abstract class PlaybackController {
"PlaybackService has no media object. Trying to restore last played media.");
Intent serviceIntent = getPlayLastPlayedMediaIntent();
if (serviceIntent != null) {
- activity.startService(serviceIntent);
+ ContextCompat.startForegroundService(activity, serviceIntent);
}
}
*/
@@ -576,6 +587,7 @@ public abstract class PlaybackController {
public void playPause() {
if (playbackService == null) {
+ PlaybackService.startService(activity, media, true, false);
Log.w(TAG, "Play/Pause button was pressed, but playbackservice was null!");
return;
}
@@ -609,6 +621,8 @@ public abstract class PlaybackController {
public int getPosition() {
if (playbackService != null) {
return playbackService.getCurrentPosition();
+ } else if (media != null) {
+ return media.getPosition();
} else {
return PlaybackService.INVALID_TIME;
}
@@ -617,12 +631,17 @@ public abstract class PlaybackController {
public int getDuration() {
if (playbackService != null) {
return playbackService.getDuration();
+ } else if (media != null) {
+ return media.getDuration();
} else {
return PlaybackService.INVALID_TIME;
}
}
public Playable getMedia() {
+ if (media == null) {
+ media = getMediaFromPreferences();
+ }
return media;
}
@@ -714,8 +733,13 @@ public abstract class PlaybackController {
}
public boolean isPlayingVideoLocally() {
- return playbackService != null && PlaybackService.getCurrentMediaType() == MediaType.VIDEO
- && !PlaybackService.isCasting();
+ if (PlaybackService.isCasting()) {
+ return false;
+ } else if (playbackService != null) {
+ return PlaybackService.getCurrentMediaType() == MediaType.VIDEO;
+ } else {
+ return getMedia() != null && getMedia().getMediaType() == MediaType.VIDEO;
+ }
}
public Pair getVideoSize() {
@@ -755,6 +779,18 @@ public abstract class PlaybackController {
}
}
+ public void resumeServiceNotRunning() {
+ if (getMedia().getMediaType() == MediaType.AUDIO) {
+ TypedArray res = activity.obtainStyledAttributes(new int[]{
+ de.danoeh.antennapod.core.R.attr.av_play_big});
+ getPlayButton().setImageResource(
+ res.getResourceId(0, de.danoeh.antennapod.core.R.drawable.ic_play_arrow_grey600_36dp));
+ res.recycle();
+ } else {
+ getPlayButton().setImageResource(R.drawable.ic_av_play_circle_outline_80dp);
+ }
+ }
+
/**
* Refreshes the current position of the media file that is playing.
*/
diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml
index 2e7cc7149..5759912d1 100644
--- a/core/src/main/res/values/strings.xml
+++ b/core/src/main/res/values/strings.xml
@@ -29,6 +29,7 @@
%1$s free
Episode cache full
The episode cache limit has been reached. You can increase the cache size in the Settings.
+ Synchronizing…
Total time of podcasts played:
@@ -719,4 +720,6 @@
Allows to control playback
Errors
Shown if something went wrong
+ gpodder.net
+ Shown while currently synchronizing