Chapter marks of streams are now loaded after playback has started
This commit is contained in:
parent
862ee40539
commit
09edb416aa
@ -198,9 +198,18 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadMetadata() throws PlayableException {
|
public void loadMetadata() throws PlayableException {
|
||||||
if (getChapters() == null) {
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadChapterMarks() {
|
||||||
|
if (getChapters() == null && !localFileAvailable()) {
|
||||||
ChapterUtils.loadChaptersFromStreamUrl(this);
|
ChapterUtils.loadChaptersFromStreamUrl(this);
|
||||||
|
if (getChapters() != null) {
|
||||||
|
FeedManager.getInstance().setFeedItem(PodcastApp.getInstance(),
|
||||||
|
item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -337,7 +346,8 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageLoaderCacheKey() {
|
public String getImageLoaderCacheKey() {
|
||||||
String out = new Playable.DefaultPlayableImageLoader(this).getImageLoaderCacheKey();
|
String out = new Playable.DefaultPlayableImageLoader(this)
|
||||||
|
.getImageLoaderCacheKey();
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
if (item.getFeed().getImage() != null) {
|
if (item.getFeed().getImage() != null) {
|
||||||
return item.getFeed().getImage().getImageLoaderCacheKey();
|
return item.getFeed().getImage().getImageLoaderCacheKey();
|
||||||
|
@ -152,6 +152,8 @@ public class PlaybackService extends Service {
|
|||||||
/** True if mediaplayer was paused because it lost audio focus temporarily */
|
/** True if mediaplayer was paused because it lost audio focus temporarily */
|
||||||
private boolean pausedBecauseOfTransientAudiofocusLoss;
|
private boolean pausedBecauseOfTransientAudiofocusLoss;
|
||||||
|
|
||||||
|
private Thread chapterLoader;
|
||||||
|
|
||||||
private final IBinder mBinder = new LocalBinder();
|
private final IBinder mBinder = new LocalBinder();
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
@ -272,6 +274,9 @@ public class PlaybackService extends Service {
|
|||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Service is about to be destroyed");
|
Log.d(TAG, "Service is about to be destroyed");
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
|
if (chapterLoader != null) {
|
||||||
|
chapterLoader.interrupt();
|
||||||
|
}
|
||||||
disableSleepTimer();
|
disableSleepTimer();
|
||||||
unregisterReceiver(headsetDisconnected);
|
unregisterReceiver(headsetDisconnected);
|
||||||
unregisterReceiver(shutdownReceiver);
|
unregisterReceiver(shutdownReceiver);
|
||||||
@ -337,7 +342,7 @@ public class PlaybackService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
super.onStartCommand(intent, flags, startId);
|
super.onStartCommand(intent, flags, startId);
|
||||||
|
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "OnStartCommand called");
|
Log.d(TAG, "OnStartCommand called");
|
||||||
int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
||||||
@ -617,6 +622,27 @@ public class PlaybackService extends Service {
|
|||||||
media.setDuration(mp.getDuration());
|
media.setDuration(mp.getDuration());
|
||||||
}
|
}
|
||||||
setStatus(PlayerStatus.PREPARED);
|
setStatus(PlayerStatus.PREPARED);
|
||||||
|
if (chapterLoader != null) {
|
||||||
|
chapterLoader.interrupt();
|
||||||
|
}
|
||||||
|
chapterLoader = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Chapter loader started");
|
||||||
|
if (media != null && media.getChapters() == null) {
|
||||||
|
media.loadChapterMarks();
|
||||||
|
if (!isInterrupted() && media.getChapters() != null) {
|
||||||
|
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD,
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG, "Chapter loader stopped");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
chapterLoader.start();
|
||||||
|
|
||||||
if (startWhenPrepared) {
|
if (startWhenPrepared) {
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
@ -962,7 +988,8 @@ public class PlaybackService extends Service {
|
|||||||
if (media != null && media != null) {
|
if (media != null && media != null) {
|
||||||
int iconSize = getResources().getDimensionPixelSize(
|
int iconSize = getResources().getDimensionPixelSize(
|
||||||
android.R.dimen.notification_large_icon_width);
|
android.R.dimen.notification_large_icon_width);
|
||||||
icon = BitmapDecoder.decodeBitmapFromWorkerTaskResource(iconSize, media);
|
icon = BitmapDecoder.decodeBitmapFromWorkerTaskResource(
|
||||||
|
iconSize, media);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,6 @@ public class ExternalMedia implements Playable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadMetadata() throws PlayableException {
|
public void loadMetadata() throws PlayableException {
|
||||||
final String tmpFileName = "tmpExternalMediaimage";
|
|
||||||
|
|
||||||
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
|
||||||
try {
|
try {
|
||||||
mmr.setDataSource(source);
|
mmr.setDataSource(source);
|
||||||
@ -80,6 +78,11 @@ public class ExternalMedia implements Playable {
|
|||||||
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
|
.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
|
||||||
ChapterUtils.loadChaptersFromFileUrl(this);
|
ChapterUtils.loadChaptersFromFileUrl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadChapterMarks() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getEpisodeTitle() {
|
public String getEpisodeTitle() {
|
||||||
@ -214,12 +217,14 @@ public class ExternalMedia implements Playable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getImageLoaderCacheKey() {
|
public String getImageLoaderCacheKey() {
|
||||||
return new Playable.DefaultPlayableImageLoader(this).getImageLoaderCacheKey();
|
return new Playable.DefaultPlayableImageLoader(this)
|
||||||
|
.getImageLoaderCacheKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream reopenImageInputStream(InputStream input) {
|
public InputStream reopenImageInputStream(InputStream input) {
|
||||||
return new Playable.DefaultPlayableImageLoader(this).reopenImageInputStream(input);
|
return new Playable.DefaultPlayableImageLoader(this)
|
||||||
|
.reopenImageInputStream(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,11 +31,19 @@ public interface Playable extends Parcelable,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from a separate thread by the PlaybackService.
|
* This method is called from a separate thread by the PlaybackService.
|
||||||
* Playable objects should load their metadata in this method (for example:
|
* Playable objects should load their metadata in this method. This method
|
||||||
* chapter marks).
|
* should execute as quickly as possible and NOT load chapter marks if no
|
||||||
|
* local file is available.
|
||||||
*/
|
*/
|
||||||
public void loadMetadata() throws PlayableException;
|
public void loadMetadata() throws PlayableException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called from a separate thread by the PlaybackService.
|
||||||
|
* Playable objects should load their chapter marks in this method if no
|
||||||
|
* local file was available when loadMetadata() was called.
|
||||||
|
*/
|
||||||
|
public void loadChapterMarks();
|
||||||
|
|
||||||
/** Returns the title of the episode that this playable represents */
|
/** Returns the title of the episode that this playable represents */
|
||||||
public String getEpisodeTitle();
|
public String getEpisodeTitle();
|
||||||
|
|
||||||
@ -240,7 +248,8 @@ public interface Playable extends Parcelable,
|
|||||||
public InputStream reopenImageInputStream(InputStream input) {
|
public InputStream reopenImageInputStream(InputStream input) {
|
||||||
if (input instanceof PublicByteArrayInputStream) {
|
if (input instanceof PublicByteArrayInputStream) {
|
||||||
IOUtils.closeQuietly(input);
|
IOUtils.closeQuietly(input);
|
||||||
byte[] imgData = ((PublicByteArrayInputStream) input).getByteArray();
|
byte[] imgData = ((PublicByteArrayInputStream) input)
|
||||||
|
.getByteArray();
|
||||||
if (imgData != null) {
|
if (imgData != null) {
|
||||||
ByteArrayInputStream out = new ByteArrayInputStream(imgData);
|
ByteArrayInputStream out = new ByteArrayInputStream(imgData);
|
||||||
return out;
|
return out;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user