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