SYNCER

SYNCER

<amp-soundcloud> - SoundCloudの音楽を埋め込み表示する

1件

公開日:

AMPのamp-soundcloudは、SoundCloudの音楽を埋め込み表示するための要素です。

概要

名前
amp-soundcloud
可用性
Stable (安定)
サポートするレイアウト
fixed-height
必要なスクリプト
<script async custom-element="amp-soundcloud" src="https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js"></script>
検証
https://github.com/ampproject/amphtml/blob/master/extensions/amp-soundcloud/0.1/validator-amp-soundcloud.protoascii
ドキュメント
https://www.ampproject.org/docs/reference/extended/amp-soundcloud.html

属性

data-color

指定例: D36015

ウィジェットの色をカラーコードで指定する。先頭のハッシュ(#)は不要。data-visual属性がfalseの場合に有効。

デモを見る

data-secret-token

シークレットトークン。トラックが非公開のコンテンツの場合に必要。

data-trackid

指定例: 306060337

トラックID。

data-visual

指定例: true

ウィジェットの種類を真偽を表す文字列で指定する。trueを指定した場合はVisual、falseを指定した場合はClassicになる。省略した場合はfalseを指定したのと同じ扱い。

デモを見る

height

指定例: 150

高さ。

layout

指定例: fixed-height

layout属性にfixed-heightを指定しなければいけない。

共通属性

AMPの全てのタグで利用できる共通属性を指定できます。

説明

ライブラリの読み込み

amp-soundcloudを利用するには、専用のライブラリを読み込む必要があります。

HTML

<script async custom-element="amp-soundcloud" src="https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js"></script>

IDの確認

SoundCloudのトラックIDとシークレットトークンは、埋め込み用コードで確認できます。

トラックID

api.soundcloud.com/tracks/に続く番号がトラックIDです。

トラックID

<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/306060337&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>

HTML

<amp-soundcloud
	data-visual="true"
	height="300"
	layout="fixed-height"
	data-trackid="306060337">
</amp-soundcloud>

デモを開く

シークレットトークン

非公開トラックの場合、data-secret-token属性にシークレットトークンを指定する必要があります。埋め込みコードの中のsecret_token%3Dに続く文字列が、シークレットトークンです。

シークレットトークン

<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/306060323%3Fsecret_token%3Ds-hQWXD&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>

HTML

<amp-soundcloud
	data-visual="true"
	height="300"
	layout="fixed-height"
	data-trackid="306060323"
	data-secret-token="s-hQWXD">
</amp-soundcloud>

デモを開く

ビジュアルモード

ビジュアルモードでウィジェットを表示するには、data-visual属性にtrueを指定します。height属性は、300px、450px、600pxのいずれかが推奨されています。

HTML

<amp-soundcloud
	data-visual="true"
	height="300"
	layout="fixed-height"
	data-trackid="306060337">
</amp-soundcloud>

デモを開く

クラシックモード

クラシックモードでウィジェットを表示するには、data-visual属性を省略するか、falseを指定します。height属性は166pxくらいがオススメです。data-color属性にカラーコードを指定して、色を調整できます。

HTML

<amp-soundcloud
	data-visual="false"
	height="166"
	layout="fixed-height"
	data-trackid="306060337"
	data-color="d36015">
</amp-soundcloud>

デモを開く

サンプルコード

HTML

<!doctype html>
<html amp>
	<head>
		<meta charset="utf-8">
		<title>【デモ】<amp-soundcloud> - SoundCloudの音楽を埋め込み表示する</title>
		<link rel="canonical" href="https://syncer.jp/Web/AMP/Component/amp-soundcloud/">
		<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
		<style amp-custom>
			body {
				padding: 12px ;
				background-color: #fff ;
			}
		</style>
		<script type="application/ld+json">
			{
				"@context": "http://schema.org",
				"@type": "NewsArticle",
				"headline": "記事のタイトル",
				"image": [
					"eyecatch.jpg"
				],
				"datePublished": "2017-08-23T00:00:00+0900"
			}
		</script>
		<script async custom-element="amp-soundcloud" src="https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js"></script>
		<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
		<script async src="https://cdn.ampproject.org/v0.js"></script>
	</head>
	<body>

<h2>Classic</h2>
<amp-soundcloud
	height="166"
	layout="fixed-height"
	data-trackid="306060337"
	data-color="d36015">
</amp-soundcloud>

<h2>Visual</h2>
<amp-soundcloud
	height="300"
	layout="fixed-height"
	data-trackid="306060337"
	data-visual="true">
</amp-soundcloud>

	</body>
</html>

デモを開く

デモ

</head><body>までを含めて下さい。

</body> </html>

<style amp-custom>

</style>