Moved mediaplayer from DownloadService into MediaHandlerThread
This commit is contained in:
parent
56d29bd44c
commit
0f99acc360
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue