|
| 1 | +## Migration guide for release 0.1.5+1 to 1.0.0 |
| 2 | + |
| 3 | +From 1.0.0, waveform extraction has been reworked. |
| 4 | + |
| 5 | +## New extraction function |
| 6 | + |
| 7 | +```dart |
| 8 | +extractWaveformData(path: 'path', noOfSamples: 100); |
| 9 | +``` |
| 10 | + |
| 11 | +## How to use? |
| 12 | + |
| 13 | +First, extract waveform sample data using the above function which will return waveform data. Or you |
| 14 | +can directly use `preparPlayer` function and it will by default extract the waveform data. This can |
| 15 | +be disabled by setting `shouldExtractWaveform` to false. You can access waveform data |
| 16 | +using `waveformData` parameter from PlayerController or use `onCurrentExtractedWaveformData` |
| 17 | +stream to get the latest waveform data. |
| 18 | + |
| 19 | +To extract the data first set the audio file path to `path` parameter and `noOfSamples` parameter will |
| 20 | +determine no of waveform data in the returned list. So effectively it will determine no of waveform |
| 21 | +bars. |
| 22 | + |
| 23 | +Now, if you want the shorter waveforms which will fit inside the given width then you can calculate |
| 24 | +no of samples by using `getSamplesForWidth` function from `PlayerWaveStyle`. This function requires |
| 25 | +width and it will calculate no of samples based width and spacing (which was set during |
| 26 | +the initialization PlayerWaveStyle instance). |
| 27 | + |
| 28 | +Now set this value like this, |
| 29 | +```dart |
| 30 | +final samples = getSamplesForWidth(200); |
| 31 | +extractWaveformData(path: 'path', noOfSamples: samples); |
| 32 | +``` |
| 33 | +If you need longer waveform then you can pass any no of sample directly. |
| 34 | + |
| 35 | +If `preparePlayer` was used with `shouldExtractWaveform` enabled then `AudioFileWaveform` widget will |
| 36 | +directly receive the waveform data other wise you have to pass it manually. |
| 37 | + |
| 38 | +Now let's create the widget, |
| 39 | +```dart |
| 40 | +AudioFileWaveforms( |
| 41 | + size: Size(200, 100), |
| 42 | + controller: controller, |
| 43 | + waveformType: WaveformType.fitWidth, |
| 44 | + continuousWaveform: true, |
| 45 | +); |
| 46 | +``` |
| 47 | +Now, there are two types of waveforms for this, |
| 48 | +1. fitWidth |
| 49 | +2. long |
| 50 | + |
| 51 | +* fitWidth -: These waveforms are preferable for limited with as above we used. With these waveforms, |
| 52 | + we can seek through them with continuous drag gestures or tap gestures. |
| 53 | + |
| 54 | +* long -: These waveforms are preferable where waveform bars exceed the screen and need to be |
| 55 | + scrolled to reach the end. With this waveform, we can seek through only by dragging them. |
| 56 | + |
| 57 | +Extracting the waveform data is a resource heavy task so it may take some time to extract. Now based on |
| 58 | +that, you can directly show the waveforms as soon as newer values get extracted by setting |
| 59 | +`continousWaveform` to true. If it's set to false then it will wait for the whole extraction process to |
| 60 | +complete. |
| 61 | + |
| 62 | +As extraction process is resource heavy, we can directly provide waveformData to `AudioFileWaveforms` |
| 63 | +widget and it will ignore the `continuousWaveform` flag and directly show the waveforms without any waiting. |
| 64 | +So the process will be as below, |
| 65 | +```dart |
| 66 | +final waveformData = await extractWaveformData(path: 'path', noOfSamples: samples); |
| 67 | + ... |
| 68 | +AudioFileWaveforms( |
| 69 | + waveformData: waveformData, |
| 70 | +); |
| 71 | +``` |
| 72 | + |
| 73 | +Now one last thing, as these waveformData have very small values, We can scale using scaleFactor. |
| 74 | +And to provide some scale feedback while scrolling we can use scrollScale to scale waves while scrolling |
| 75 | +and they will be scaled down to the original scale when scrolling ends. |
| 76 | +```dart |
| 77 | +PlayerWaveStyle( |
| 78 | + scaleFactor: 100, |
| 79 | + scrollScale: 1.2, |
| 80 | +); |
| 81 | +``` |
| 82 | + |
| 83 | +To see the list of all parameters and detailed description of parameters visit [documentation](https://pub.dev/documentation/audio_waveforms/latest/audio_waveforms/audio_waveforms-library.html). |
0 commit comments