如何从 iOS Swift 中的 waveformdata 对象绘制波形?
How to draw waveform from waveformdata object in iOS Swift?
[
{
"id": "48250",
"created_at": "2014-07-06 13:05:10",
"user_id": "7",
"duration": "7376",
"permalink": "shawne-back-to-the-roots-2-05072014",
"description": "Years: 2000 - 2005\r\nSet Time: Warm Up (11 pm - 01 am)\r\n",
"downloadable": "1",
"genre": "Drum & Bass",
"genre_slush": "drumandbass",
"title": "Shawne @ Back To The Roots 2 (05.07.2014)",
"uri": "https:\/\/api-v2.hearthis.at\/\/shawne-back-to-the-roots-2-05072014\/",
"permalink_url": "http:\/\/hearthis.at\/\/shawne-back-to-the-roots-2-05072014\/",
"artwork_url": "http:\/\/hearthis.at\/_\/cache\/images\/track\/500\/801982cafc20a06ccf6203f21f10c08d_w500.png",
"background_url": "",
"waveform_data": "http:\/\/hearthis.at\/_\/wave_data\/7\/3000_4382f398c454c47cf171aab674cf00f0.mp3.js",
"waveform_url": "http:\/\/hearthis.at\/_\/wave_image\/7\/4382f398c454c47cf171aab674cf00f0.mp3.png",
"user": {
"id": "7",
"permalink": "shawne",
"username": "Shawne (hearthis.at)",
"uri": "https:\/\/api-v2.hearthis.at\/shawne\/",
"permalink_url": "http:\/\/hearthis.at\/shawne\/",
"avatar_url": "http:\/\/hearthis.at\/_\/cache\/images\/user\/512\/06a8299b0e7d8f2909a22697badd7c09_w512.jpg"
},
"stream_url": "http:\/\/hearthis.at\/shawne\/shawne-back-to-the-roots-2-05072014\/listen\/",
"download_url": "http:\/\/hearthis.at\/shawne\/shawne-back-to-the-roots-2-05072014\/download\/",
"playback_count": "75",
"download_count": "9",
"favoritings_count": "7",
"favorited": false,
"comment_count": "0"
}
]
这个Apireturns波形url和波形数据。如何转换波形数据以在波形url
中绘制类似于图像的波形
看起来 "data" 只是一连串的条形高度:
[136,132,133,133,138,...]
所以只需在这些高度(或与它们成比例的高度)绘制一连串条形。您可能需要每隔 n 个条绘制一次,或者可能需要将 n 个条的每个块平均在一起,以获得更整洁的表示(这就是他们在您指向的站点上所做的)。
[
{
"id": "48250",
"created_at": "2014-07-06 13:05:10",
"user_id": "7",
"duration": "7376",
"permalink": "shawne-back-to-the-roots-2-05072014",
"description": "Years: 2000 - 2005\r\nSet Time: Warm Up (11 pm - 01 am)\r\n",
"downloadable": "1",
"genre": "Drum & Bass",
"genre_slush": "drumandbass",
"title": "Shawne @ Back To The Roots 2 (05.07.2014)",
"uri": "https:\/\/api-v2.hearthis.at\/\/shawne-back-to-the-roots-2-05072014\/",
"permalink_url": "http:\/\/hearthis.at\/\/shawne-back-to-the-roots-2-05072014\/",
"artwork_url": "http:\/\/hearthis.at\/_\/cache\/images\/track\/500\/801982cafc20a06ccf6203f21f10c08d_w500.png",
"background_url": "",
"waveform_data": "http:\/\/hearthis.at\/_\/wave_data\/7\/3000_4382f398c454c47cf171aab674cf00f0.mp3.js",
"waveform_url": "http:\/\/hearthis.at\/_\/wave_image\/7\/4382f398c454c47cf171aab674cf00f0.mp3.png",
"user": {
"id": "7",
"permalink": "shawne",
"username": "Shawne (hearthis.at)",
"uri": "https:\/\/api-v2.hearthis.at\/shawne\/",
"permalink_url": "http:\/\/hearthis.at\/shawne\/",
"avatar_url": "http:\/\/hearthis.at\/_\/cache\/images\/user\/512\/06a8299b0e7d8f2909a22697badd7c09_w512.jpg"
},
"stream_url": "http:\/\/hearthis.at\/shawne\/shawne-back-to-the-roots-2-05072014\/listen\/",
"download_url": "http:\/\/hearthis.at\/shawne\/shawne-back-to-the-roots-2-05072014\/download\/",
"playback_count": "75",
"download_count": "9",
"favoritings_count": "7",
"favorited": false,
"comment_count": "0"
}
]
这个Apireturns波形url和波形数据。如何转换波形数据以在波形url
中绘制类似于图像的波形看起来 "data" 只是一连串的条形高度:
[136,132,133,133,138,...]
所以只需在这些高度(或与它们成比例的高度)绘制一连串条形。您可能需要每隔 n 个条绘制一次,或者可能需要将 n 个条的每个块平均在一起,以获得更整洁的表示(这就是他们在您指向的站点上所做的)。