我正在尝试将列表解析/转换MediaItem
为 a ConcatenatingAudioSource
,但我的单元测试不断给我一个错误,即转换ConcatenatingAudioSource
后的与目标源不匹配。我的测试是
List<MediaItem> audioSource = <MediaItem>[
MediaItem(
// This can be any unique id, but we use the audio URL for convenience.
id: "https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3",
album: "Science Friday",
title: "A Salute To Head-Scratching Science",
artist: "Science Friday and WNYC Studios",
duration: Duration(milliseconds: 5739820),
artUri: Uri.parse(
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg"),
),
MediaItem(
id: "https://s3.amazonaws.com/scifri-segments/scifri201711241.mp3",
album: "Science Friday",
title: "From Cat Rheology To Operatic Incompetence",
artist: "Science Friday and WNYC Studios",
duration: Duration(milliseconds: 2856950),
artUri: Uri.parse(
"https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg"),
),
];
test('mediaItem2ConcatenatingAudioSource test', () {
expect(
// Here's where the conversion happens
ConcatenatingAudioSource(
children: audioSource
.map((item) => AudioSource.uri(Uri.parse(item.id)))
.toList(),
),
ConcatenatingAudioSource(children: [
AudioSource.uri(Uri.parse(
'https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3')),
AudioSource.uri(Uri.parse(
"https://s3.amazonaws.com/scifri-segments/scifri201711241.mp3")),
]),
);
});
我得到的错误如下。我相信这是在说两者ConcatenatingAudioSource
不一样,它们应该在哪里。
Expected: <Instance of 'ConcatenatingAudioSource'>
Actual: <Instance of 'ConcatenatingAudioSource'>
我从字面上复制了audio_service
示例中的转换部分(第 362 行),所以我真的很困惑这里出了什么问题。(当我的实际应用程序运行时,此转换代码也不起作用。我将actual
测试的一部分放在setSource()
方法 thenplay()
中,但没有任何反应。)
任何帮助,将不胜感激!谢谢!