Player 開発者の基本:カスタムプラグイン - データの受け渡し
このトピックでは、カスタムプラグインにデータを渡す方法を学びます。
ステップ
- カスタムプラグインコードに、
options
プラグインを定義する無名関数内のパラメーター。
videojs.registerPlugin('navigateOnVideoEnd', function (options) {
var myPlayer = this;
...
});
- カスタマイズのためにあなたのプラグインコードでパラメータオブジェクトの望ましいプロパティを使用してください:
videojs.registerPlugin('navigateOnVideoEnd', function (options) {
var myPlayer = this;
...
window.location.href = options.redirectURL;
});
- プラグインを呼び出すHTMLページで、必要な1つまたは複数のプロパティを使用してオブジェクトを構築します。
<script>
videojs.getPlayer('myPlayerID').ready(function() {
var myPlayer = this,
options = {"redirectURL": "http://support.brightcove.com"};
...
});
</script>
- カスタムプラグインを呼び出すときは、
options
パラメータとしてのオブジェクト
<script>
videojs.getPlayer('myPlayerID').ready(function() {
var myPlayer = this,
options = {"redirectURL": "http://support.brightcove.com"};
myPlayer.navigateOnVideoEnd(options);
});
</script>
- 使用している場合 Studio、オプションオブジェクトをカスタムプラグインに オプション(JSON) フォーム要素:
完全なコード
プラグインコード
videojs.registerPlugin('navigateOnVideoEnd', function (options) {
var myPlayer = this;
myPlayer.on('ended', function () {
window.location.href = options.redirectURL;
});
});
HTMLページ呼び出しコード
<video-js id="myPlayerID"
data-video-id="5701193190001"
data-account="1752604059001"
data-player="default"
data-embed="default"
data-application-id
class="video-js"
controls
width="640"
height="360"></video-js>
<script src="//players.brightcove.net/1752604059001/default_default/index.min.js"></script>
<script src="redirect.js"></script>
<script>
videojs.getPlayer('myPlayerID').ready(function() {
var myPlayer = this,
options = {"redirectURL": "http://support.brightcove.com"};
myPlayer.navigateOnVideoEnd(options);
});
</script>