一个性能极高的可定制波形视图。提取资产(可以是视频或音频)的音频部分,并显示波形。
SCWaveformView 优化为了尽可能少地读取文件。当滚动或显示波形的另一部分时,它只会读取渲染新部分所需的内容。它将文件数据缓存起来,以避免读取已计算的部分。此外,如果确实需要读取文件,它将通过较大的段读取以最大限度地减少下次时间范围更改时的读取操作数量。
主要功能
此项目灵感来源于 https://github.com/fulldecent/FDWaveformView
// Allocating the waveformview
SCWaveformView *waveformView = [[SCWaveformView alloc] init];
// Setting the asset
AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@"blabla.mp3"]];
waveformView.asset = asset;
// Setting the waveform colors
waveformView.normalColor = [UIColor greenColor];
waveformView.progressColor = [UIColor redColor];
// Set the play progress
waveformView.progressTime = CMTimeMakeWithSeconds(5, 10000);
// Show only the first second of your asset
waveformView.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(1, 1));
// Use it inside a scrollView
SCScrollableWaveformView *scrollableWaveformView = [SCScrollableWaveformView new];
scrollableWaveformView.waveformView; // Access the waveformView from there
// Set the precision, 1 being the maximum
waveformView.precision = 0.25; // We are going to render one line per four pixels
// Set the lineWidth so we have some space between the lines
waveformView.lineWidthRatio = 0.5;