Difference between revisions of "Video/Audio Plugin"
(30 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This is a small plugin guide to create your own video/audio plugin. It is designed for developers who have web programming skills (e.g. HTML, JavaScript, CSS, etc.). By the way, from the technical point of view, there are no differences between a video plugin and an audio plugin. You can load a video plugin as an audio plugin and vice versa. Therefore, there is only one API for both. | This is a small plugin guide to create your own video/audio plugin. It is designed for developers who have web programming skills (e.g. HTML, JavaScript, CSS, etc.). By the way, from the technical point of view, there are no differences between a video plugin and an audio plugin. You can load a video plugin as an audio plugin and vice versa. Therefore, there is only one API for both. | ||
− | '''Note: For basic video/audio plugins, version 0.1.40 or higher is needed. For full-featured video/audio plugins, version 0.1.74 or higher is needed.''' | + | '''Note: For basic video/audio plugins, version 0.1.40 or higher is needed. For full-featured video/audio plugins, version 0.1.74 or higher is needed. Please note that it is recommended to only use the JavaScript ES5 (ECMAScript 2009) syntax for plugins, because most (especially older) TV browsers do not support the newer JavaScript ES6 (ECMAScript 2015) syntax. Please also note that newer JavaScript classes/libraries may not be supported by all TV browsers. Therefore, you should implement a good error handling to detect unsupported platforms.''' |
== Basics == | == Basics == | ||
A video/audio plugin is nothing more than a simple HTML page that is loaded into an iframe. You do not even need to add any JavaScript or CSS file. Therefore, any HTML page can be loaded as a video/audio plugin (at least if the page does not refuse it via the <code>X-Frame-Options</code> HTTP header). Please see following example screenshot & code. | A video/audio plugin is nothing more than a simple HTML page that is loaded into an iframe. You do not even need to add any JavaScript or CSS file. Therefore, any HTML page can be loaded as a video/audio plugin (at least if the page does not refuse it via the <code>X-Frame-Options</code> HTTP header). Please see following example screenshot & code. | ||
+ | |||
+ | === Screenshot === | ||
+ | [[File:my_plugin1.png|thumb|640px|none|Example Screenshot (My Video/Audio Plugin 1/2)]] | ||
'''Note: The background color of the iframe is black.''' | '''Note: The background color of the iframe is black.''' | ||
− | + | === Code === | |
− | |||
<syntaxhighlight lang="html"> | <syntaxhighlight lang="html"> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
Line 31: | Line 33: | ||
A video/audio plugin will not receive any input (i.e. it is not possible to handle key, mouse, or touch events). Therefore, you should not implement any controls or buttons, because they can not be controlled anyway. The only task of a video/audio plugin is to show/play the video/audio output. All interactions (e.g. to set/get the current position, to set/get the playback speed, etc.) are managed by the <code>TVXVideoPlugin</code> interface. Add the JavaScript file http://msx.benzac.de/js/tvx-plugin.min.js to your HTML page to make this interface available. Additionally, add some JavaScript lines to interact with this interface. Please see following example screenshot & code. | A video/audio plugin will not receive any input (i.e. it is not possible to handle key, mouse, or touch events). Therefore, you should not implement any controls or buttons, because they can not be controlled anyway. The only task of a video/audio plugin is to show/play the video/audio output. All interactions (e.g. to set/get the current position, to set/get the playback speed, etc.) are managed by the <code>TVXVideoPlugin</code> interface. Add the JavaScript file http://msx.benzac.de/js/tvx-plugin.min.js to your HTML page to make this interface available. Additionally, add some JavaScript lines to interact with this interface. Please see following example screenshot & code. | ||
+ | === Screenshot === | ||
[[File:my_plugin2.png|thumb|640px|none|Example Screenshot (My Video/Audio Plugin 2/2)]] | [[File:my_plugin2.png|thumb|640px|none|Example Screenshot (My Video/Audio Plugin 2/2)]] | ||
+ | === Code === | ||
<syntaxhighlight lang="html"> | <syntaxhighlight lang="html"> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
Line 44: | Line 48: | ||
} | } | ||
</style> | </style> | ||
− | <script type="text/javascript" src=" | + | <script type="text/javascript" src="//msx.benzac.de/js/tvx-plugin.min.js"></script> |
<script type="text/javascript"> | <script type="text/javascript"> | ||
function MyPlayer() { | function MyPlayer() { | ||
Line 107: | Line 111: | ||
}; | }; | ||
} | } | ||
− | + | TVXPluginTools.onReady(function() { | |
TVXVideoPlugin.setupPlayer(new MyPlayer()); | TVXVideoPlugin.setupPlayer(new MyPlayer()); | ||
TVXVideoPlugin.init(); | TVXVideoPlugin.init(); | ||
− | }; | + | }); |
</script> | </script> | ||
</head> | </head> | ||
Line 118: | Line 122: | ||
</html> | </html> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | '''Note: It is recommended to reference the <code>tvx-plugin.min.js</code> file without the protocol prefix (i.e. <code>http:</code> or <code>https:</code>) to support insecure and secure connections.''' | ||
== API == | == API == | ||
Line 124: | Line 129: | ||
== Examples == | == Examples == | ||
Here are some examples that you can use as reference to implement your own video/audio plugin. Just open the implementation script or the link from the action syntax and analyze it with your browser developer tools (e.g. Chrome Developer Tools). | Here are some examples that you can use as reference to implement your own video/audio plugin. Just open the implementation script or the link from the action syntax and analyze it with your browser developer tools (e.g. Chrome Developer Tools). | ||
− | |||
− | |||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
Line 132: | Line 135: | ||
! Plugin !! Implementation Script & Related API Link !! Action Syntax | ! Plugin !! Implementation Script & Related API Link !! Action Syntax | ||
|- | |- | ||
− | | Template || http://msx.benzac.de/plugins/js/template.js || | + | | Template || |
+ | http://msx.benzac.de/plugins/js/template.js<br/> | ||
+ | || | ||
<code>video:plugin:http://msx.benzac.de/plugins/template.html</code><br/> | <code>video:plugin:http://msx.benzac.de/plugins/template.html</code><br/> | ||
<code>audio:plugin:http://msx.benzac.de/plugins/template.html</code><br/> | <code>audio:plugin:http://msx.benzac.de/plugins/template.html</code><br/> | ||
+ | |- | ||
+ | | HTML5 || | ||
+ | http://msx.benzac.de/plugins/js/html5.js<br/> | ||
+ | https://www.w3.org/TR/2011/WD-html5-20110113/video.html<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/html5.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/html5.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | Dash || | ||
+ | http://msx.benzac.de/plugins/js/dash.js<br/> | ||
+ | https://cdn.dashjs.org/latest/jsdoc/index.html<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/dash.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/dash.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | Shaka || | ||
+ | http://msx.benzac.de/plugins/js/shaka.js<br/> | ||
+ | https://shaka-player-demo.appspot.com/docs/api/index.html<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/shaka.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/shaka.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | HAS || | ||
+ | http://msx.benzac.de/plugins/js/has.js<br/> | ||
+ | https://orange-opensource.github.io/hasplayer.js/latest/doc/jsdoc/index.html<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/has.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/has.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | HLS || | ||
+ | http://msx.benzac.de/plugins/js/hls.js<br/> | ||
+ | https://github.com/video-dev/hls.js<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/hls.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/hls.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | Video.js || | ||
+ | http://msx.benzac.de/plugins/js/videojs.js<br/> | ||
+ | https://docs.videojs.com/player<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/videojs.html?url={URL}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/videojs.html?url={URL}</code><br/> | ||
+ | |- | ||
+ | | YouTube || | ||
+ | http://msx.benzac.de/plugins/js/youtube.js<br/> | ||
+ | https://developers.google.com/youtube/iframe_api_reference<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/youtube.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/youtube.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | Vimeo || | ||
+ | http://msx.benzac.de/plugins/js/vimeo.js<br/> | ||
+ | https://github.com/vimeo/player.js<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/vimeo.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/vimeo.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | Dailymotion || | ||
+ | http://msx.benzac.de/plugins/js/dailymotion.js<br/> | ||
+ | https://developer.dailymotion.com/player<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/dailymotion.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/dailymotion.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | Twitch || | ||
+ | http://msx.benzac.de/plugins/js/twitch.js<br/> | ||
+ | https://dev.twitch.tv/docs/embed/video-and-clips<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/twitch.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/twitch.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | Facebook || | ||
+ | http://msx.benzac.de/plugins/js/facebook.js<br/> | ||
+ | https://developers.facebook.com/docs/plugins/embedded-video-player/api/<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/facebook.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/facebook.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | Wistia || | ||
+ | http://msx.benzac.de/plugins/js/wistia.js<br/> | ||
+ | https://wistia.com/support/developers/player-api<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/wistia.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/wistia.html?id={ID}</code><br/> | ||
+ | |- | ||
+ | | SoundCloud || | ||
+ | http://msx.benzac.de/plugins/js/soundcloud.js<br/> | ||
+ | https://developers.soundcloud.com/docs/api/html5-widget<br/> | ||
+ | || | ||
+ | <code>video:plugin:http://msx.benzac.de/plugins/soundcloud.html?id={ID}</code><br/> | ||
+ | <code>audio:plugin:http://msx.benzac.de/plugins/soundcloud.html?id={ID}</code><br/> | ||
|} | |} | ||
Line 165: | Line 261: | ||
"title": "Example Video", | "title": "Example Video", | ||
"playerLabel": "YouTube - Example Video", | "playerLabel": "YouTube - Example Video", | ||
− | "action": "video:plugin:http://msx.benzac.de/plugins/youtube.html?id= | + | "action": "video:plugin:http://msx.benzac.de/plugins/youtube.html?id=PRy2CFVlPOA" |
}, { | }, { | ||
"badge": "{txt:msx-white:Vimeo}", | "badge": "{txt:msx-white:Vimeo}", | ||
Line 209: | Line 305: | ||
* Launch via App: https://msx.benzac.de/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json | * Launch via App: https://msx.benzac.de/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json | ||
* Launch via Demo Page: https://msx.benzac.de/info/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json | * Launch via Demo Page: https://msx.benzac.de/info/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json | ||
+ | |||
+ | == See also == | ||
+ | * [[Plugin API Reference]] |
Latest revision as of 12:02, 12 June 2023
This is a small plugin guide to create your own video/audio plugin. It is designed for developers who have web programming skills (e.g. HTML, JavaScript, CSS, etc.). By the way, from the technical point of view, there are no differences between a video plugin and an audio plugin. You can load a video plugin as an audio plugin and vice versa. Therefore, there is only one API for both.
Note: For basic video/audio plugins, version 0.1.40 or higher is needed. For full-featured video/audio plugins, version 0.1.74 or higher is needed. Please note that it is recommended to only use the JavaScript ES5 (ECMAScript 2009) syntax for plugins, because most (especially older) TV browsers do not support the newer JavaScript ES6 (ECMAScript 2015) syntax. Please also note that newer JavaScript classes/libraries may not be supported by all TV browsers. Therefore, you should implement a good error handling to detect unsupported platforms.
Basics[edit]
A video/audio plugin is nothing more than a simple HTML page that is loaded into an iframe. You do not even need to add any JavaScript or CSS file. Therefore, any HTML page can be loaded as a video/audio plugin (at least if the page does not refuse it via the X-Frame-Options
HTTP header). Please see following example screenshot & code.
Screenshot[edit]
Note: The background color of the iframe is black.
Code[edit]
<!DOCTYPE html>
<html>
<head>
<title>My Video/Audio Plugin</title>
<style type="text/css">
h1 {
font-family: sans-serif;
color: white;
}
</style>
</head>
<body>
<h1>My Video/Audio Plugin</h1>
</body>
</html>
Interactions[edit]
A video/audio plugin will not receive any input (i.e. it is not possible to handle key, mouse, or touch events). Therefore, you should not implement any controls or buttons, because they can not be controlled anyway. The only task of a video/audio plugin is to show/play the video/audio output. All interactions (e.g. to set/get the current position, to set/get the playback speed, etc.) are managed by the TVXVideoPlugin
interface. Add the JavaScript file http://msx.benzac.de/js/tvx-plugin.min.js to your HTML page to make this interface available. Additionally, add some JavaScript lines to interact with this interface. Please see following example screenshot & code.
Screenshot[edit]
Code[edit]
<!DOCTYPE html>
<html>
<head>
<title>My Video/Audio Plugin</title>
<style type="text/css">
h1 {
font-family: sans-serif;
color: white;
}
</style>
<script type="text/javascript" src="//msx.benzac.de/js/tvx-plugin.min.js"></script>
<script type="text/javascript">
function MyPlayer() {
this.init = function() {
//Init player
};
this.ready = function() {
//Player is ready
TVXVideoPlugin.startPlayback();//This will call the play function and will start the update process
};
this.play = function() {
//Play
};
this.pause = function() {
//Pause
};
this.stop = function() {
//Stop
};
this.getDuration = function() {
//Get duration in seconds
return 60;
};
this.getPosition = function() {
//Get position in seconds
return 0;
};
this.setPosition = function(position) {
//Set position in seconds
if (position == 60) {
TVXVideoPlugin.stopPlayback();//Generally, this will unload the iframe
}
};
this.setVolume = function(volume) {
//Set volume (0 .. 100)
};
this.getVolume = function() {
//Get volume (0 .. 100)
return 100;
};
this.setMuted = function(muted) {
//Set muted
};
this.isMuted = function() {
//Get muted
return false;
};
this.getSpeed = function() {
//Get speed (0.125 .. 8.0)
return 1;
};
this.setSpeed = function(speed) {
//Set speed (0.125 .. 8.0)
};
this.getUpdateData = function() {
//Get update data (this will be called each second)
return {
position: this.getPosition(),
duration: this.getDuration(),
speed: this.getSpeed()
};
};
}
TVXPluginTools.onReady(function() {
TVXVideoPlugin.setupPlayer(new MyPlayer());
TVXVideoPlugin.init();
});
</script>
</head>
<body>
<h1>My Video/Audio Plugin</h1>
</body>
</html>
Note: It is recommended to reference the tvx-plugin.min.js
file without the protocol prefix (i.e. http:
or https:
) to support insecure and secure connections.
API[edit]
Beside the TVXVideoPlugin
interface, the JavaScript file exposes some more classes. Please see Plugin API Reference for more information.
Examples[edit]
Here are some examples that you can use as reference to implement your own video/audio plugin. Just open the implementation script or the link from the action syntax and analyze it with your browser developer tools (e.g. Chrome Developer Tools).
Screenshot[edit]
Code[edit]
{
"type": "list",
"headline": "Video Plugin Test",
"template": {
"type": "separate",
"layout": "0,0,2,4",
"icon": "msx-white-soft:extension",
"color": "msx-glass"
},
"items": [{
"title": "Template",
"playerLabel": "Template",
"action": "video:plugin:http://msx.benzac.de/plugins/template.html"
}, {
"badge": "{txt:msx-white:Html5}",
"badgeColor": "#000000",
"title": "Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/html5.html?url=http://msx.benzac.de/media/video3.mp4"
}, {
"badge": "{txt:msx-white:YouTube}",
"badgeColor": "#ff0000",
"title": "Example Video",
"playerLabel": "YouTube - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/youtube.html?id=PRy2CFVlPOA"
}, {
"badge": "{txt:msx-white:Vimeo}",
"badgeColor": "#1ab7ea",
"title": "Example Video",
"playerLabel": "Vimeo - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/vimeo.html?id=54802209"
}, {
"badge": "{txt:msx-white:Dailymotion}",
"badgeColor": "#00aaff",
"title": "Example Video",
"playerLabel": "Dailymotion - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/dailymotion.html?id=xz14c1"
}, {
"badge": "{txt:msx-white:Twitch}",
"badgeColor": "#643fa6",
"title": "Example Video",
"playerLabel": "Twitch - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/twitch.html?id=499763039"
}, {
"badge": "{txt:msx-white:Facebook}",
"badgeColor": "#4767aa",
"title": "Example Video",
"playerLabel": "Facebook - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/facebook.html?id=10152454700553553"
}, {
"badge": "{txt:msx-white:Wistia}",
"badgeColor": "#5aaff2",
"title": "Example Video",
"playerLabel": "Wistia - Example Video",
"action": "video:plugin:http://msx.benzac.de/plugins/wistia.html?id=ve7pzy0d3y"
}, {
"badge": "{txt:msx-white:SoundCloud}",
"badgeColor": "#ff5500",
"title": "Example Track",
"playerLabel": "SoundCloud - Example Track",
"action": "video:plugin:http://msx.benzac.de/plugins/soundcloud.html?id=143041228"
}]
}
Demo[edit]
- Launch via App: https://msx.benzac.de/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json
- Launch via Demo Page: https://msx.benzac.de/info/?start=content:https://msx.benzac.de/info/xp/data/plugin_test_1.json