How to Embed
Songle Widget is an externally embedded player dedicated to the "Songle" web service for active music listening. You can embed a Songle Widget in your webpage or blog. If you are a programmer, you will be able to develop a music-synchronized application with the Songle Widget.
Please copy the following HTML code to the location where you want to display the Songle Widget in your webpage or blog. You can change the song by altering the Songle URL.
<div data-api="songle-widget-api-example" data-url="www.youtube.com/watch?v=PqJNc9KVIZE" id="songle-widget"></div>
<script src="https://widget.songle.jp/v1/widgets.js"></script>
Summary
Songle Widget API allows the programmer to create and control Songle Widgets by writing a simple piece of JavaScript code.
1. Basics
By inserting the script tag and adding data-api and data-url attributes to any block elements, Songle Widgets are automatically initialized upon page loading.
A. Embed by HTML Code
<div data-api="songle-widget-api-example" data-url="www.youtube.com/watch?v=PqJNc9KVIZE" id="songle-widget"></div>
<script src="https://widget.songle.jp/v1/widgets.js"></script>
B. Embed by JavaScript Code
<script src="https://widget.songle.jp/v1/api.js"></script>
window.onload =
function()
{
var songleWidgetElement =
SongleWidgetAPI.createSongleWidgetElement({
api: "songle-widget-api-example",
url: "www.youtube.com/watch?v=PqJNc9KVIZE"
});
document.body.appendChild(songleWidgetElement);
}
Since data-api attribute of embed code is used to distinguish each Songle Widget, its value is recommended to be unique for each widget.
2. Hello,Songle Widget!!
In the following example, a pop-up dialog appears when Songle Widget API is ready to be used.
window.onSongleWidgetReady =
function(apiKey, songleWidget)
{
console.log("Hello,Songle Widget!!");
}
3. Example
Songle Widget API enables your program to react to a music-related event (such as beats and chords) by using the event handler of JavaScript.
window.onSongleWidgetReady =
function(apiKey, songleWidget)
{
songleWidget.on("beatPlay",
function(e)
{
switch(e.beat.position)
{
case 1:
// You can write code for the 1st beat ...
console.log("1st beat");
break;
case 2:
// You can write code for the 2nd beat ...
console.log("2nd beat");
break;
case 3:
// You can write code for the 3rd beat ...
console.log("3rd beat");
break;
case 4:
// You can write code for the 4th beat ...
console.log("4th beat");
break;
}
});
songleWidget.play(); // Start playing song.
}
Requirements
| Web browser | Version |
|---|---|
| Microsoft Internet Explorer | 9,10,11 |
| Microsoft Edge | 14 |
| Mozilla Firefox | 48 |
| Google Chrome | 52 (recommended) |
| Safari | 9 |
| Opera | 39 |
| Android Browser | 51 |
| Google Chrome for Android | 51 |
Related documents
- JavaScript API — control the embedded widget from your scripts (
SongleWidgetclass, events, control methods) - REST API — fetch song analysis data (beat, chord, melody, chorus)
- Plugins — extension plugins (photos, shapes, music structures) and embedding options