如何使Soundcloud嵌入端点返回高度为300的iframe?

时间:2019-02-28 07:59:10

标签: soundcloud oembed

我正在使用souncloud的oembed端点,默认高度为400,这太大了。

我需要调整它,我已经尝试过了:

https://soundcloud.com/oembed?format=json&height=300&url=https://soundcloud.com/giorgiomartini

但这只会改变图稿的高度,注意html键(iframe)末尾的高度,在json上,我会得到返回:

{
"version": 1,
"type": "rich",
"provider_name": "SoundCloud",
"provider_url": "http://soundcloud.com",
"height": 450,
"width": "100%",
"title": "Giorgio Martini",
"description": null,
"thumbnail_url": "http://i1.sndcdn.com/avatars-000336450748-qnkjy0-t500x500.jpg",
"html": "<iframe width=\"100%\" height=\"450\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?visual=true&url=https%3A%2F%2Fapi.soundcloud.com%2Fusers%2F1367858&show_artwork=true&height=300\"></iframe>",
"author_name": "Giorgio Martini",
"author_url": "https://soundcloud.com/giorgiomartini"
}

但是我确实需要更改iframe本身的高度...有没有办法做到这一点?

还是我必须对返回的响应进行某种字符串操作以将高度从400更改为300?

谢谢

2 个答案:

答案 0 :(得分:1)

根据documentation,有一个名为maxheight的URL参数-只需将其设置为300:

https://soundcloud.com/oembed?format=json&maxheight=300&url=https://soundcloud.com/giorgiomartini

答案 1 :(得分:1)

我建议改用CSS来使视频iframe响应,因此无论在任何设备上窗口的大小如何,它始终会填充其父容器。请参见Fluid Width Video和VideoWrapper类。