【发布时间】:2023-03-21 23:04:01
【问题描述】:
我想创建一个具有类似于 SoundCloud 的视图的音乐应用程序,这个要明确:This
我想为每个栏创建一个这样的类:
class Bar {
const Bar(this.alreadyPlayed, this.index, this.height);
final bool alreadyPlayed;
final int index;
final double height;
}
其中 alreadyPlayed 是一个布尔值,指示条形图是应该着色还是变灰,index 是条形图的编号和高度,well 是条形的高度。前两个变量应该不难获取,我的问题是获取bar的高度,即当时音乐的强度。这已经足够了,但如果有人知道如何计算特定频率的强度,例如 225 Hz,那就更好了。
但无论如何,如果有帮助,我将在伪代码中添加我想要实现的功能:
// Obtain the mp3 file.
//
// Define a number of bars decided from the song length
// or from a default, for example, 80.
//
// In a loop that goes from 0 to the number of bars create
// a Bar Object with the default alreadyPlayed as 0, index
// as the index and the height as a 0.
//
// Obtain the intensity of the sound in a way like this:
// sound[time_in_milliseconds = song_lenght_in_milliseconds / num_of_bars ],
// and then set the height of the bar as the just found intensity.
我问的可能吗?
【问题讨论】:
-
您有解码 MP3 文件的经验吗?或者为此考虑一个图书馆?我不知道有任何直接执行此操作的 dart 库,这意味着您必须在本机代码中执行此操作并将其连接到与平台通道一起颤动,除非您有一个想法....
-
我找到了在此应用程序中使用的音频播放器插件 (pub.dartlang.org/packages/audioplayer):youtube.com/watch?v=FE7Vtzq52xg 用于类似的范围。但我不知道这是否可以使用同一个库来完成。我真的不知道如何解码 mp3。那么原生代码和使用平台通道连接到 Flutter 是什么意思?
-
嗨。您找到获取波形的解决方案了吗?