我希望创建一个音乐应用程序,其视图类似于SoundCloud,清晰地指的是这个:这个
我想为每个条形创建一个类,类似于:
class Bar {
const Bar(this.alreadyPlayed, this.index, this.height);
final bool alreadyPlayed;
final int index;
final double height;
}
其中,alreadyPlayed是一个布尔值,用于判断条形图是否应该被涂色或变灰,index是条形图的编号,height是条形图的高度。前两个变量应该不难获取,我的问题是如何获取条形图的高度,即此时音乐的强度。这已经足够了,但如果有人知道如何计算特定频率(例如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.
“我所问的是否可能?”