Skip to content

Commit a652a16

Browse files
authored
Merge pull request #377 from mumu-lhl/feat/support-any-audio-format
feat(audio): support any audio format
2 parents 07cce02 + aa088a9 commit a652a16

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/database/app/daos.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,11 @@ class MddAudioResourceDao extends DatabaseAccessor<AppDatabase>
338338
.go();
339339
}
340340

341-
Future<MddAudioResourceData?> getByKeyAndMddAudioID(
341+
Future<List<MddAudioResourceData>?> getByKeyAndMddAudioID(
342342
String key, int mddAudioId) async {
343343
return (await (select(mddAudioResource)
344344
..where(
345345
(t) => t.key.isValue(key) & t.mddAudioListId.isValue(mddAudioId)))
346-
.getSingleOrNull());
346+
.get());
347347
}
348348
}

lib/services/audio.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "package:ciyue/database/app/app.dart";
66
import "package:ciyue/main.dart";
77
import "package:ciyue/services/dictionary.dart";
88
import "package:dict_reader/dict_reader.dart";
9+
import "package:mime/mime.dart";
910
import "package:path/path.dart";
1011
import "package:path_provider/path_provider.dart";
1112

@@ -23,15 +24,20 @@ Future<void> playSoundOfWord(
2324
final player = AudioPlayer();
2425

2526
for (final mddAudio in mddAudioList) {
26-
final audio = await mddAudioResourceDao.getByKeyAndMddAudioID(
27+
final audios = await mddAudioResourceDao.getByKeyAndMddAudioID(
2728
"$word.spx", mddAudio.id);
28-
if (audio != null) {
29+
for (final audio in audios!) {
30+
if (setExtension(audio.key, "") != word) {
31+
continue;
32+
}
33+
2934
final reader = DictReader(mddAudio.path);
3035
await reader.init(false);
3136

3237
final Uint8List data = await reader.readOne(audio.blockOffset,
3338
audio.startOffset, audio.endOffset, audio.compressedSize);
34-
await player.setSourceBytes(data, mimeType: "audio/x-speex");
39+
final mimeType = lookupMimeType(audio.key);
40+
await player.setSourceBytes(data, mimeType: mimeType);
3541

3642
await player.resume();
3743

0 commit comments

Comments
 (0)