Moved mediaplayer from DownloadService into MediaHandlerThread

This commit is contained in:
daniel oeh 2012-09-16 13:16:13 +02:00
parent 56d29bd44c
commit 0f99acc360
1 changed files with 9 additions and 9 deletions

View File

@ -101,8 +101,7 @@ public class DownloadService extends Service {
private NotificationCompat.Builder notificationBuilder;
private int NOTIFICATION_ID = 2;
private int REPORT_ID = 3;
/** Needed to determine the duration of a media file */
private MediaPlayer mediaplayer;
private List<Downloader> downloads;
@ -179,7 +178,6 @@ public class DownloadService extends Service {
});
manager = FeedManager.getInstance();
requester = DownloadRequester.getInstance();
mediaplayer = new MediaPlayer();
}
@Override
@ -192,7 +190,6 @@ public class DownloadService extends Service {
if (AppConfig.DEBUG)
Log.d(TAG, "Service shutting down");
isRunning = false;
mediaplayer.release();
unregisterReceiver(cancelDownloadReceiver);
unregisterReceiver(downloadQueued);
}
@ -674,17 +671,20 @@ public class DownloadService extends Service {
public void run() {
media.setDownloaded(true);
// Get duration
MediaPlayer mediaplayer = new MediaPlayer();
try {
mediaplayer.setDataSource(media.getFile_url());
mediaplayer.prepare();
media.setDuration(mediaplayer.getDuration());
if (AppConfig.DEBUG)
Log.d(TAG, "Duration of file is " + media.getDuration());
mediaplayer.reset();
} catch (IOException e) {
e.printStackTrace();
} finally {
mediaplayer.release();
}
media.setDuration(mediaplayer.getDuration());
if (AppConfig.DEBUG)
Log.d(TAG, "Duration of file is " + media.getDuration());
mediaplayer.reset();
saveDownloadStatus(status);
sendDownloadHandledIntent(DOWNLOAD_TYPE_MEDIA);
manager.setFeedMedia(DownloadService.this, media);