From e9e27d8cb6c4cec20587a08660546fc1c653123f Mon Sep 17 00:00:00 2001 From: stonegate Date: Wed, 19 Aug 2020 18:09:05 +0800 Subject: [PATCH] Fixed bug, downlaoded file play error. --- lib/local_storage/sqflite_localpodcast.dart | 12 ------------ lib/state/download_state.dart | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/local_storage/sqflite_localpodcast.dart b/lib/local_storage/sqflite_localpodcast.dart index 335de08..e985290 100644 --- a/lib/local_storage/sqflite_localpodcast.dart +++ b/lib/local_storage/sqflite_localpodcast.dart @@ -1177,12 +1177,6 @@ class DBHelper { list.first['is_new'], mediaId: list.first['media_id'], skipSeconds: list.first['skip_seconds']); - if (episode.enclosureUrl != episode.mediaId && - !File(episode.mediaId.substring(7)).existsSync()) { - final url = episode.enclosureUrl; - await delDownloaded(url); - episode = episode.copyWith(mediaId: url); - } return episode; } } @@ -1211,12 +1205,6 @@ class DBHelper { list.first['is_new'], mediaId: list.first['media_id'], skipSeconds: list.first['skip_seconds']); - if (episode.enclosureUrl != episode.mediaId && - !File(episode.mediaId.substring(7)).existsSync()) { - final url = episode.enclosureUrl; - await delDownloaded(url); - episode = episode.copyWith(mediaId: url); - } return episode; } } diff --git a/lib/state/download_state.dart b/lib/state/download_state.dart index aaf40c8..f9eeab7 100644 --- a/lib/state/download_state.dart +++ b/lib/state/download_state.dart @@ -151,7 +151,7 @@ class DownloadState extends ChangeNotifier { super.addListener(listener); } - _loadTasks() async { + Future _loadTasks() async { _episodeTasks = []; var dbHelper = DBHelper(); var tasks = await FlutterDownloader.loadTasks(); @@ -162,8 +162,21 @@ class DownloadState extends ChangeNotifier { await FlutterDownloader.remove( taskId: task.taskId, shouldDeleteContent: true); } else { - _episodeTasks.add(EpisodeTask(episode, task.taskId, - progress: task.progress, status: task.status)); + if (task.status == DownloadTaskStatus.complete) { + var exist = + await File(path.join(task.savedDir, task.filename)).exists(); + if (!exist) { + await FlutterDownloader.remove( + taskId: task.taskId, shouldDeleteContent: true); + await dbHelper.delDownloaded(episode.enclosureUrl); + } else { + _episodeTasks.add(EpisodeTask(episode, task.taskId, + progress: task.progress, status: task.status)); + } + } else { + _episodeTasks.add(EpisodeTask(episode, task.taskId, + progress: task.progress, status: task.status)); + } } } }