Made PlaybackService use the PSMP and PSTM
This commit is contained in:
parent
cfb3861fd0
commit
e05a5c265b
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ import android.media.RemoteControlClient;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.feed.Chapter;
|
||||
import de.danoeh.antennapod.feed.MediaType;
|
||||
@ -73,6 +74,7 @@ public class PlaybackServiceMediaPlayer {
|
||||
statusBeforeSeeking = null;
|
||||
pausedBecauseOfTransientAudiofocusLoss = false;
|
||||
mediaType = MediaType.UNKNOWN;
|
||||
playerStatus = PlayerStatus.STOPPED;
|
||||
}
|
||||
|
||||
private Handler.Callback handlerCallback = new Handler.Callback() {
|
||||
@ -475,6 +477,10 @@ public class PlaybackServiceMediaPlayer {
|
||||
return startWhenPrepared.get();
|
||||
}
|
||||
|
||||
public void setStartWhenPrepared(boolean startWhenPrepared) {
|
||||
this.startWhenPrepared.set(startWhenPrepared);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the playback speed can be adjusted. This method can also return false if the PSMP object's
|
||||
* internal MediaPlayer cannot be accessed at the moment.
|
||||
@ -523,10 +529,36 @@ public class PlaybackServiceMediaPlayer {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current playback speed. If the playback speed could not be retrieved, 1 is returned.
|
||||
*/
|
||||
public float getPlaybackSpeed() {
|
||||
if (!playerLock.tryLock()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int retVal = 1;
|
||||
if (playerStatus == PlayerStatus.PLAYING
|
||||
|| playerStatus == PlayerStatus.PAUSED
|
||||
|| playerStatus == PlayerStatus.PREPARED) {
|
||||
retVal = mediaPlayer.getCurrentPosition();
|
||||
} else if (media != null && media.getPosition() > 0) {
|
||||
retVal = media.getPosition();
|
||||
}
|
||||
|
||||
playerLock.unlock();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public MediaType getCurrentMediaType() {
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
public boolean isStreaming() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Releases internally used resources. This method should only be called when the object is not used anymore.
|
||||
*/
|
||||
@ -537,6 +569,33 @@ public class PlaybackServiceMediaPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
public void setVideoSurface(final SurfaceHolder surface) {
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playerLock.lock();
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.setDisplay(surface);
|
||||
}
|
||||
playerLock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void resetVideoSurface() {
|
||||
executor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
playerLock.lock();
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Resetting video surface");
|
||||
mediaPlayer.setDisplay(null);
|
||||
reinit();
|
||||
playerLock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PSMInfo object that contains information about the current state of the PSMP object.
|
||||
*
|
||||
|
@ -83,8 +83,8 @@ public class PlayerWidgetService extends Service {
|
||||
PlaybackService.getPlayerActivityIntent(this), 0);
|
||||
|
||||
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
|
||||
if (playbackService != null && playbackService.getMedia() != null) {
|
||||
Playable media = playbackService.getMedia();
|
||||
final Playable media = playbackService.getPlayable();
|
||||
if (playbackService != null && media != null) {
|
||||
PlayerStatus status = playbackService.getStatus();
|
||||
|
||||
views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
|
||||
@ -126,8 +126,8 @@ public class PlayerWidgetService extends Service {
|
||||
}
|
||||
|
||||
private String getProgressString(PlaybackService ps) {
|
||||
int position = ps.getCurrentPositionSafe();
|
||||
int duration = ps.getDurationSafe();
|
||||
int position = ps.getCurrentPosition();
|
||||
int duration = ps.getDuration();
|
||||
if (position != PlaybackService.INVALID_TIME
|
||||
&& duration != PlaybackService.INVALID_TIME) {
|
||||
return Converter.getDurationStringLong(position) + " / "
|
||||
|
@ -30,6 +30,7 @@ import de.danoeh.antennapod.AppConfig;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.feed.Chapter;
|
||||
import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.feed.MediaType;
|
||||
import de.danoeh.antennapod.preferences.PlaybackPreferences;
|
||||
import de.danoeh.antennapod.service.playback.PlaybackService;
|
||||
import de.danoeh.antennapod.service.playback.PlayerStatus;
|
||||
@ -157,7 +158,7 @@ public abstract class PlaybackController {
|
||||
*/
|
||||
public void pause() {
|
||||
mediaInfoLoaded = false;
|
||||
if (playbackService != null && playbackService.isPlayingVideo()) {
|
||||
if (playbackService != null && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
playbackService.pause(true, true);
|
||||
}
|
||||
}
|
||||
@ -488,7 +489,7 @@ public abstract class PlaybackController {
|
||||
Log.d(TAG, "Querying service info");
|
||||
if (playbackService != null) {
|
||||
status = playbackService.getStatus();
|
||||
media = playbackService.getMedia();
|
||||
media = playbackService.getPlayable();
|
||||
if (media == null) {
|
||||
Log.w(TAG,
|
||||
"PlaybackService has no media object. Trying to restore last played media.");
|
||||
@ -541,7 +542,7 @@ public abstract class PlaybackController {
|
||||
*/
|
||||
public void onSeekBarStopTrackingTouch(SeekBar seekBar, float prog) {
|
||||
if (playbackService != null) {
|
||||
playbackService.seek((int) (prog * media.getDuration()));
|
||||
playbackService.seekTo((int) (prog * media.getDuration()));
|
||||
setupPositionObserver();
|
||||
}
|
||||
}
|
||||
@ -557,7 +558,7 @@ public abstract class PlaybackController {
|
||||
break;
|
||||
case PAUSED:
|
||||
case PREPARED:
|
||||
playbackService.play();
|
||||
playbackService.resume();
|
||||
break;
|
||||
case PREPARING:
|
||||
playbackService.setStartWhenPrepared(!playbackService
|
||||
@ -569,7 +570,7 @@ public abstract class PlaybackController {
|
||||
break;
|
||||
case INITIALIZED:
|
||||
playbackService.setStartWhenPrepared(true);
|
||||
playbackService.prepare();
|
||||
playbackService.resume();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -609,7 +610,7 @@ public abstract class PlaybackController {
|
||||
|
||||
public int getPosition() {
|
||||
if (playbackService != null) {
|
||||
return playbackService.getCurrentPositionSafe();
|
||||
return playbackService.getCurrentPosition();
|
||||
} else {
|
||||
return PlaybackService.INVALID_TIME;
|
||||
}
|
||||
@ -617,7 +618,7 @@ public abstract class PlaybackController {
|
||||
|
||||
public int getDuration() {
|
||||
if (playbackService != null) {
|
||||
return playbackService.getDurationSafe();
|
||||
return playbackService.getDuration();
|
||||
} else {
|
||||
return PlaybackService.INVALID_TIME;
|
||||
}
|
||||
@ -691,7 +692,7 @@ public abstract class PlaybackController {
|
||||
|
||||
public boolean isPlayingVideo() {
|
||||
if (playbackService != null) {
|
||||
return PlaybackService.isPlayingVideo();
|
||||
return PlaybackService.getCurrentMediaType() == MediaType.VIDEO;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -716,7 +717,7 @@ public abstract class PlaybackController {
|
||||
*/
|
||||
public void reinitServiceIfPaused() {
|
||||
if (playbackService != null
|
||||
&& playbackService.isShouldStream()
|
||||
&& playbackService.isStreaming()
|
||||
&& (playbackService.getStatus() == PlayerStatus.PAUSED || (playbackService
|
||||
.getStatus() == PlayerStatus.PREPARING && playbackService
|
||||
.isStartWhenPrepared() == false))) {
|
||||
@ -733,8 +734,7 @@ public abstract class PlaybackController {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (playbackService != null && playbackService.getPlayer() != null
|
||||
&& playbackService.getPlayer().isPlaying()) {
|
||||
if (playbackService != null && playbackService.getStatus() == PlayerStatus.PLAYING) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user