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.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.SurfaceHolder;
|
||||||
import de.danoeh.antennapod.AppConfig;
|
import de.danoeh.antennapod.AppConfig;
|
||||||
import de.danoeh.antennapod.feed.Chapter;
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.MediaType;
|
import de.danoeh.antennapod.feed.MediaType;
|
||||||
@ -73,6 +74,7 @@ public class PlaybackServiceMediaPlayer {
|
|||||||
statusBeforeSeeking = null;
|
statusBeforeSeeking = null;
|
||||||
pausedBecauseOfTransientAudiofocusLoss = false;
|
pausedBecauseOfTransientAudiofocusLoss = false;
|
||||||
mediaType = MediaType.UNKNOWN;
|
mediaType = MediaType.UNKNOWN;
|
||||||
|
playerStatus = PlayerStatus.STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Handler.Callback handlerCallback = new Handler.Callback() {
|
private Handler.Callback handlerCallback = new Handler.Callback() {
|
||||||
@ -475,6 +477,10 @@ public class PlaybackServiceMediaPlayer {
|
|||||||
return startWhenPrepared.get();
|
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
|
* 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.
|
* 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() {
|
public MediaType getCurrentMediaType() {
|
||||||
return mediaType;
|
return mediaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStreaming() {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases internally used resources. This method should only be called when the object is not used anymore.
|
* 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.
|
* 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);
|
PlaybackService.getPlayerActivityIntent(this), 0);
|
||||||
|
|
||||||
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
|
views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
|
||||||
if (playbackService != null && playbackService.getMedia() != null) {
|
final Playable media = playbackService.getPlayable();
|
||||||
Playable media = playbackService.getMedia();
|
if (playbackService != null && media != null) {
|
||||||
PlayerStatus status = playbackService.getStatus();
|
PlayerStatus status = playbackService.getStatus();
|
||||||
|
|
||||||
views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
|
views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
|
||||||
@ -126,8 +126,8 @@ public class PlayerWidgetService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getProgressString(PlaybackService ps) {
|
private String getProgressString(PlaybackService ps) {
|
||||||
int position = ps.getCurrentPositionSafe();
|
int position = ps.getCurrentPosition();
|
||||||
int duration = ps.getDurationSafe();
|
int duration = ps.getDuration();
|
||||||
if (position != PlaybackService.INVALID_TIME
|
if (position != PlaybackService.INVALID_TIME
|
||||||
&& duration != PlaybackService.INVALID_TIME) {
|
&& duration != PlaybackService.INVALID_TIME) {
|
||||||
return Converter.getDurationStringLong(position) + " / "
|
return Converter.getDurationStringLong(position) + " / "
|
||||||
|
@ -30,6 +30,7 @@ import de.danoeh.antennapod.AppConfig;
|
|||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.feed.Chapter;
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.FeedMedia;
|
import de.danoeh.antennapod.feed.FeedMedia;
|
||||||
|
import de.danoeh.antennapod.feed.MediaType;
|
||||||
import de.danoeh.antennapod.preferences.PlaybackPreferences;
|
import de.danoeh.antennapod.preferences.PlaybackPreferences;
|
||||||
import de.danoeh.antennapod.service.playback.PlaybackService;
|
import de.danoeh.antennapod.service.playback.PlaybackService;
|
||||||
import de.danoeh.antennapod.service.playback.PlayerStatus;
|
import de.danoeh.antennapod.service.playback.PlayerStatus;
|
||||||
@ -157,7 +158,7 @@ public abstract class PlaybackController {
|
|||||||
*/
|
*/
|
||||||
public void pause() {
|
public void pause() {
|
||||||
mediaInfoLoaded = false;
|
mediaInfoLoaded = false;
|
||||||
if (playbackService != null && playbackService.isPlayingVideo()) {
|
if (playbackService != null && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||||
playbackService.pause(true, true);
|
playbackService.pause(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,7 +489,7 @@ public abstract class PlaybackController {
|
|||||||
Log.d(TAG, "Querying service info");
|
Log.d(TAG, "Querying service info");
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
status = playbackService.getStatus();
|
status = playbackService.getStatus();
|
||||||
media = playbackService.getMedia();
|
media = playbackService.getPlayable();
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
Log.w(TAG,
|
Log.w(TAG,
|
||||||
"PlaybackService has no media object. Trying to restore last played media.");
|
"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) {
|
public void onSeekBarStopTrackingTouch(SeekBar seekBar, float prog) {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
playbackService.seek((int) (prog * media.getDuration()));
|
playbackService.seekTo((int) (prog * media.getDuration()));
|
||||||
setupPositionObserver();
|
setupPositionObserver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -557,7 +558,7 @@ public abstract class PlaybackController {
|
|||||||
break;
|
break;
|
||||||
case PAUSED:
|
case PAUSED:
|
||||||
case PREPARED:
|
case PREPARED:
|
||||||
playbackService.play();
|
playbackService.resume();
|
||||||
break;
|
break;
|
||||||
case PREPARING:
|
case PREPARING:
|
||||||
playbackService.setStartWhenPrepared(!playbackService
|
playbackService.setStartWhenPrepared(!playbackService
|
||||||
@ -569,7 +570,7 @@ public abstract class PlaybackController {
|
|||||||
break;
|
break;
|
||||||
case INITIALIZED:
|
case INITIALIZED:
|
||||||
playbackService.setStartWhenPrepared(true);
|
playbackService.setStartWhenPrepared(true);
|
||||||
playbackService.prepare();
|
playbackService.resume();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -609,7 +610,7 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
return playbackService.getCurrentPositionSafe();
|
return playbackService.getCurrentPosition();
|
||||||
} else {
|
} else {
|
||||||
return PlaybackService.INVALID_TIME;
|
return PlaybackService.INVALID_TIME;
|
||||||
}
|
}
|
||||||
@ -617,7 +618,7 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
return playbackService.getDurationSafe();
|
return playbackService.getDuration();
|
||||||
} else {
|
} else {
|
||||||
return PlaybackService.INVALID_TIME;
|
return PlaybackService.INVALID_TIME;
|
||||||
}
|
}
|
||||||
@ -691,7 +692,7 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
public boolean isPlayingVideo() {
|
public boolean isPlayingVideo() {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
return PlaybackService.isPlayingVideo();
|
return PlaybackService.getCurrentMediaType() == MediaType.VIDEO;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -716,7 +717,7 @@ public abstract class PlaybackController {
|
|||||||
*/
|
*/
|
||||||
public void reinitServiceIfPaused() {
|
public void reinitServiceIfPaused() {
|
||||||
if (playbackService != null
|
if (playbackService != null
|
||||||
&& playbackService.isShouldStream()
|
&& playbackService.isStreaming()
|
||||||
&& (playbackService.getStatus() == PlayerStatus.PAUSED || (playbackService
|
&& (playbackService.getStatus() == PlayerStatus.PAUSED || (playbackService
|
||||||
.getStatus() == PlayerStatus.PREPARING && playbackService
|
.getStatus() == PlayerStatus.PREPARING && playbackService
|
||||||
.isStartWhenPrepared() == false))) {
|
.isStartWhenPrepared() == false))) {
|
||||||
@ -733,8 +734,7 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (playbackService != null && playbackService.getPlayer() != null
|
if (playbackService != null && playbackService.getStatus() == PlayerStatus.PLAYING) {
|
||||||
&& playbackService.getPlayer().isPlaying()) {
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user