Chapter marks of streams are now loaded after playback has started

This commit is contained in:
daniel oeh 2013-03-25 12:38:17 +01:00
parent 862ee40539
commit 09edb416aa
4 changed files with 62 additions and 11 deletions

View File

@ -198,9 +198,18 @@ public class FeedMedia extends FeedFile implements Playable {
@Override
public void loadMetadata() throws PlayableException {
if (getChapters() == null) {
}
@Override
public void loadChapterMarks() {
if (getChapters() == null && !localFileAvailable()) {
ChapterUtils.loadChaptersFromStreamUrl(this);
if (getChapters() != null) {
FeedManager.getInstance().setFeedItem(PodcastApp.getInstance(),
item);
}
}
}
@Override
@ -337,7 +346,8 @@ public class FeedMedia extends FeedFile implements Playable {
@Override
public String getImageLoaderCacheKey() {
String out = new Playable.DefaultPlayableImageLoader(this).getImageLoaderCacheKey();
String out = new Playable.DefaultPlayableImageLoader(this)
.getImageLoaderCacheKey();
if (out == null) {
if (item.getFeed().getImage() != null) {
return item.getFeed().getImage().getImageLoaderCacheKey();

View File

@ -152,6 +152,8 @@ public class PlaybackService extends Service {
/** True if mediaplayer was paused because it lost audio focus temporarily */
private boolean pausedBecauseOfTransientAudiofocusLoss;
private Thread chapterLoader;
private final IBinder mBinder = new LocalBinder();
public class LocalBinder extends Binder {
@ -272,6 +274,9 @@ public class PlaybackService extends Service {
if (AppConfig.DEBUG)
Log.d(TAG, "Service is about to be destroyed");
isRunning = false;
if (chapterLoader != null) {
chapterLoader.interrupt();
}
disableSleepTimer();
unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver);
@ -617,6 +622,27 @@ public class PlaybackService extends Service {
media.setDuration(mp.getDuration());
}
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) {
play();
}
@ -962,7 +988,8 @@ public class PlaybackService extends Service {
if (media != null && media != null) {
int iconSize = getResources().getDimensionPixelSize(
android.R.dimen.notification_large_icon_width);
icon = BitmapDecoder.decodeBitmapFromWorkerTaskResource(iconSize, media);
icon = BitmapDecoder.decodeBitmapFromWorkerTaskResource(
iconSize, media);
}
}

View File

@ -62,8 +62,6 @@ public class ExternalMedia implements Playable {
@Override
public void loadMetadata() throws PlayableException {
final String tmpFileName = "tmpExternalMediaimage";
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
try {
mmr.setDataSource(source);
@ -81,6 +79,11 @@ public class ExternalMedia implements Playable {
ChapterUtils.loadChaptersFromFileUrl(this);
}
@Override
public void loadChapterMarks() {
}
@Override
public String getEpisodeTitle() {
return episodeTitle;
@ -214,12 +217,14 @@ public class ExternalMedia implements Playable {
@Override
public String getImageLoaderCacheKey() {
return new Playable.DefaultPlayableImageLoader(this).getImageLoaderCacheKey();
return new Playable.DefaultPlayableImageLoader(this)
.getImageLoaderCacheKey();
}
@Override
public InputStream reopenImageInputStream(InputStream input) {
return new Playable.DefaultPlayableImageLoader(this).reopenImageInputStream(input);
return new Playable.DefaultPlayableImageLoader(this)
.reopenImageInputStream(input);
}
}

View File

@ -31,11 +31,19 @@ public interface Playable extends Parcelable,
/**
* This method is called from a separate thread by the PlaybackService.
* Playable objects should load their metadata in this method (for example:
* chapter marks).
* Playable objects should load their metadata in this method. This method
* should execute as quickly as possible and NOT load chapter marks if no
* local file is available.
*/
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 */
public String getEpisodeTitle();
@ -240,7 +248,8 @@ public interface Playable extends Parcelable,
public InputStream reopenImageInputStream(InputStream input) {
if (input instanceof PublicByteArrayInputStream) {
IOUtils.closeQuietly(input);
byte[] imgData = ((PublicByteArrayInputStream) input).getByteArray();
byte[] imgData = ((PublicByteArrayInputStream) input)
.getByteArray();
if (imgData != null) {
ByteArrayInputStream out = new ByteArrayInputStream(imgData);
return out;