SoundCloud API 요청에서 직접 원 웨이브 폼 데이터를 가져 오는 공식적인 방법은 없지만이를 사용하여 PHP에서 비공식 엔드 포인트 (일명 : https://wis.sndcdn.com/XwA2iPEIVF8z_m.json
등)의 정확한 데이터를 파생시키는 방법이 있습니다. 이 같은 코드. 그 https://wis.sndcdn.com/
URL이 유용하지만
이
$source_width = 1800;
$source_height = 140;
$image_file = 'https://w1.sndcdn.com/XwA2iPEIVF8z_m.png';
$image_processed = imagecreatefrompng($image_file);
imagealphablending($image_processed, true);
imagesavealpha($image_processed, true);
$waveform_data = array();
for ($width = 0; $width < $source_width; $width++) {
for ($height = 0; $height < $source_height; $height++) {
$color_index = @imagecolorat($image_processed, $width, $height);
// Determine the colors—and alpha—of the pixels like this.
$rgb_array = imagecolorsforindex($image_processed, $color_index);
// Peak detection is based on matching a transparent PNG value.
$match_color_index = array(0, 0, 0, 127);
$diff_value = array_diff($match_color_index, array_values($rgb_array));
if (empty($diff_value)) {
break;
}
} // $height loop.
// Value is based on the delta between the actual height versus detected height.
$waveform_data[] = $source_height - $height;
} // $width loop.
// Dump the waveform data array to check the values.
echo '<pre>';
print_r($waveform_data);
echo '</pre>';
이 방법의 장점은, 어떤 이야기가 없습니다 : 단순히 당신이 있고 당신이 가고 좋은 280 높은 PNG 이미지 너비 어떤 사운드 클라우드 1800에 맞게 $image_file
의 값을 변경 SoundCloud가 데이터 구조를 변경하는 경우/때.공식 파형에서 데이터를 파생하는 것은 PNG 이미지를 SoundCloud API 최종 사용자에게 공평한 경고없이 변경하려는 것이기 때문에 장기간 안정성을 제공합니다.
또한 $source_width
은 1800이지만은 140입니다. SoundCloud PNG 파일의 높이가 280 픽셀 인 반면, 아래쪽 절반은 기본적으로 뒤집기/뒤집힌 복사본입니다. 0에서 150까지의 값을 측정하면 필요한 파형 데이터 값을 얻을 수 있습니다.