通知中心封面图显示
部分界面的信息更新 缓存系统初步引入 即将进入播放列表更新
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class ArtworkHelper {
|
||||
static const String _artworkDir = 'artworks';
|
||||
|
||||
/// 保存封面图到本地
|
||||
static Future<String?> saveArtwork(Uint8List data, String songKey) async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
@@ -24,7 +24,6 @@ class ArtworkHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取封面图文件
|
||||
static Future<File?> getArtwork(String songKey) async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
@@ -39,7 +38,6 @@ class ArtworkHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除封面图
|
||||
static Future<void> deleteArtwork(String songKey) async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
@@ -47,6 +45,7 @@ class ArtworkHelper {
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
debugPrint('🗑️ [ArtworkHelper] deleted artwork: $songKey');
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// lib/utils/file_provider_utils.dart
|
||||
import 'dart:io';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class FileProviderUtils {
|
||||
static const MethodChannel _channel =
|
||||
MethodChannel('com.lxh.qingting_player/file_provider');
|
||||
|
||||
/// 生成 content:// URI(Android only)
|
||||
static Future<Uri?> getContentUri(File file) async {
|
||||
if (!Platform.isAndroid) {
|
||||
// 非 Android 平台直接返回 file:// URI
|
||||
return Uri.file(file.path);
|
||||
}
|
||||
|
||||
try {
|
||||
final uriString = await _channel.invokeMethod('getContentUri', {
|
||||
'path': file.path,
|
||||
});
|
||||
if (uriString is String && uriString.isNotEmpty) {
|
||||
return Uri.parse(uriString);
|
||||
}
|
||||
return Uri.file(file.path);
|
||||
} on PlatformException catch (e) {
|
||||
debugPrint('⚠️ [FileProviderUtils] PlatformException: ${e.message}');
|
||||
return Uri.file(file.path);
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ [FileProviderUtils] Error: $e');
|
||||
return Uri.file(file.path);
|
||||
}
|
||||
}
|
||||
|
||||
/// 检查文件是否存在
|
||||
static Future<bool> fileExists(String path) async {
|
||||
try {
|
||||
final file = File(path);
|
||||
return await file.exists();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 删除文件
|
||||
static Future<void> deleteFile(String path) async {
|
||||
try {
|
||||
final file = File(path);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user